Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add custom attribute to Wordpress wp_editor text-area ?

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 ?

like image 381
Kapil Yadav Avatar asked Dec 21 '16 05:12

Kapil Yadav


1 Answers

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>
like image 90
Ankur Bhadania Avatar answered Oct 09 '22 00:10

Ankur Bhadania