7

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 ?

Kapil Yadav
  • 650
  • 1
  • 5
  • 29

1 Answers1

3

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>
Ankur Bhadania
  • 4,123
  • 1
  • 23
  • 38