Make wp_editor required

by Darth Mikey D   Last Updated May 15, 2019 15:08 PM

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;
}
Tags : php wp-editor


Related Questions


Updated March 26, 2015 09:02 AM

Updated May 17, 2015 21:03 PM

Updated November 08, 2017 16:08 PM

Updated August 17, 2016 08:03 AM

Updated May 25, 2019 03:08 AM