0

I am trying to build a content submission form on the front end of my site, and I am using wp_editor to render visual text editors for my users, so they can make bold text and lists and stuff like that. The issue is that I can't figure out how to make the wp_editor a required field in my form. I know I can do the following for a standard text area.

<textarea id="content" name="content" required="required"></textarea>

that will make the browser itself recognize that it is a required field. No JavaScript jQuery or anything else needed. I need to accomplish the same thing with wp_editor, which does generate a textarea.

1 Answer 1

3

You can add a filter to the editor html

add_filter( 'the_editor', '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;
}
1
  • An invalid form control with name='subtitle' is not focusable. I got above error. Mar 29, 2021 at 7:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.