6

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.

6 Answers 6

10

Paragraph tags are added upon display, not upon storage. The wpautop() function is added as a filter to the_content.

You won't ever see these added paragraph tags in either the visual or HTML editors.

7
  • Seems a bit silly no? Paragraphs are, well, paragraphs: why not wrap them in the appropriate markup?
    – gravyface
    Jun 1, 2012 at 18:46
  • You're welcome to write a patch to change the behavior, but I doubt it would get implemented. :) Jun 1, 2012 at 18:49
  • I'll live with it. Where abouts would I go to re-enable this? I just grep'ed through the theme directory for wpautop with no results.
    – gravyface
    Jun 1, 2012 at 18:54
  • Re-enable what, exactly? wpautop() is added as a filter to the_content, in wp-includes/default-filters.php. Jun 1, 2012 at 19:14
  • 1
    Odd, it's there (add_filter( 'the_content', 'wpautop' );), but when I create a new page, type a paragraph, add a line break (and highlight the text and choose "paragraph" from the styles, it looks great in the visual editor but when I publish it, there's no paragraph tags wrapping it; this is why I've been adding them manually in the HTML tab.
    – gravyface
    Jun 1, 2012 at 19:37
7

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".

4

Make sure you are using the_content for calling the post content and not something like get_the_content. WordPress wpautop filter is applied on the_content.

1
  • That no makes any difference in the visual editor. Read the question again.
    – cybmeta
    Nov 21, 2014 at 10:54
0

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.

0

nl2br() can be used to add the line breaks again when using the filtered HTML again

-3

The 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 add remove_filter('the_content', 'wpautop'); the content is displayed without p tags.

In both cases, the content editor is displayed in the same manner

3
  • 4
    That’s what Chip said. What is the point of this answer?
    – fuxia
    Jan 4, 2013 at 18:04
  • It was supposed to be a comment, a supplement to the explanation made ​​by Chip Bennett. Jan 24, 2013 at 2:52
  • 1
    If it was supposed to be a "comment," it should be a comment...
    – Dan
    Jan 24, 2013 at 3:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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