WordPress strips out <p>
and <br>
tags when switching between the visual and the text editors. Well, to be specific, it doesn’t actually strip them out of the content, but it does not display them in the text editor view. Is there a way to stop it from hiding those tags?
I know about the tinymce advanced plugin, but is there a way to stop this behavior on a per-post/per-page basis without having to install the plugin?
If you add a meaningless data attribute to the
<p>
and<br>
tags, they will continue to show.Example
When switching from text to visual editor and back, the following text
becomes
However,
makes the tags remain visible:
This is useful on pages with more complex layouts that can shift around when the tags get stripped.
If the post is custom post type, you can add meta box with add_meta_box and there you can initialize your own editor with wp_editor which can be customized. For example you can pass settings to the tinymce like
force_p_newslines
which should force every new line to start with new paragraph