How to add custom attribute to wordpp wp_editor text area?

How to add custom attributes to wp_editor Wordpress text box?

There is no way in the White Papers to do this. I need to add a client-side validation attribute (data-bvalidator = "required") to the text area that is created by the wp_editor WordPress method.

Any suggestions?

+6
source share
1 answer

I think there is no way to add custom attributes to wp_editor()

Therefore, you need to add a custom attribute to the text-area field using JQuery

First add an extra class to the text-area editor

 $settings = array( ...... 'editor_class' => 'customclass_for_addattr', ...... ); wp_editor( $content, $editor_id, $settings ); 

After the wp_editor () function adds the jQuery code below. it adds 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> 
+1
source

Source: https://habr.com/ru/post/1013376/


All Articles