How to add custom attributes to Wordpress wp_editor textarea field ?
In Official documentation there is no way to do this. I need to add client side validation attribute (data-bvalidator="required") to text-area which is generated by wp_editor method of WordPress.
Any suggestions ?
I think there are not an option for adding custom attributes in wp_editor()
So you need to add custom Attribute in text-area
field using JQuery
First add extra class(es) to the editor text-area
$settings = array(
......
'editor_class' => 'customclass_for_addattr',
......
);
wp_editor( $content, $editor_id, $settings );
After wp_editor() function add below jQuery code. it's add the custom attribute to text-area
using jQuery atrr
method
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery(".customclass_for_addattr").attr('data-bvalidator','required');
});
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With