Make wp_editor required

I have a page with multiple wp_editors. I need to make 2 of them required. I tried the following, but it didn’t work. I did put it right after the function that loads the page, but not sure if it should be somewhere else. Any help is appreciated.

Code to load the wp_editor

$content = “”;
$editorid = “statement”;
$settings = array(
‘textarea_name’ => ‘statement’,
‘editor_height’ => 100,
‘quicktags’ => false,
‘media_buttons’ => false,
‘teeny’ => true,
‘tinymce’=> array(
‘theme_advanced_disable’ => ‘fullscreen’,
‘width’ => 500,
wp_editor( $content, $editorid, $settings );

Code to make the editor required

add_filter( ‘statement’, ‘add_required_attribute_to_wp_editor’, 10, 1 );
function add_required_attribute_to_wp_editor( $editor ) {
$editor = str_replace( ‘<textarea’, ‘<textarea required=”required”‘, $editor );
return $editor;

Read more here:: Make wp_editor required

Leave a Reply

Your email address will not be published. Required fields are marked *