While working on a custom plugin, I needed to add the wp_editor in the admin to let the user add its own content.

I want the user to be able to write custom rich texts with the "Visual" editor mode but I also want the user to be able to paste HTML codes in the "Text" view. For example, if he wants to paste his subscription HTML form, he could do that while switching to the "Text" mode.

The issue is when I paste some HTML in the "Text" mode, after saving, the code renders with line breaks <br> which completely changes the way the form should look.

My question is : can I prevent Wordpress from adding these line breaks if I paste some HTML code in the editor while in "Text" mode?

I've tried setting wpautop to false :

$editor_config = array(
    "wpautop" => false,
    "media_buttons" => true

wp_editor( $content, "my_editor", $editor_config ); 

... which doesn't change anything.

  • 1
    wpautop is something that happens when it's displayed, not when its edited, there's nothing you can do to wp_editor or when editing to change that, though if you could, it would break newlines in the visual part of the editor. Perhaps you would get more mileage out of removing the <br> tags? Or using a separate box for your form markup? Perhaps a shortcode can insert it in the appropriate place inside the editor box you created? – Tom J Nowell Sep 4 '19 at 11:55

Your Answer

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

Browse other questions tagged or ask your own question.