From my Googling, it appears as though the default behavior in WordPress is to add paragraphs automatically, but in the HTML view, regardless of what style I choose in the Visual Editor’s style drop-down (paragraph, for example), paragraph tags never appear. I also do not see wpautop()
called anywhere in my theme (which I inherited from a now departed developer).
What can I do to set this straight? Adding <p>
tags to everything is obviously not going to fly with the content editors.
Paragraph tags are added upon display, not upon storage. The
wpautop()
function is added as a filter tothe_content
.You won’t ever see these added paragraph tags in either the visual or HTML editors.
One solution is to install the TinyMCE Advanced plugin. In the plugin settings you have a option “Stop removing the
<p>
and<br />
tags when saving and show Them in the HTML editor”.Make sure you are using
the_content
for calling the post content and not something likeget_the_content
. WordPresswpautop
filter is applied onthe_content
.I just struggled with this same issue and was about to loose my mind because I tried everything mentioned above and other ideas. It turned out that the client was using a Yootheme, and there is a tick box in the settings of that particular theme, which when clicked solved the issue immediately. Here’s a link to the forum post: https://yootheme.com/support/question/4342
In other words, it could be a theme related issue.
nl2br()
can be used to add the line breaks again when using the filtered HTML againThe
wpautop()
filter changes the content view but not changes the view mode on the content editor.Example:
<?php the_content(); ?>
displays the content normally. If you addremove_filter('the_content', 'wpautop');
the content is displayed withoutp
tags.In both cases, the content editor is displayed in the same manner