Make WordPress Core

Opened 6 years ago

Last modified 5 years ago

#43100 new defect (bug)

Unexpected results from wpautop

Reported by: pross's profile pross Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:


An empty paragraph will result in invalid HTML

To reproduce using default theme add echo wpautop( '<p></p>' ); into a template file.

Expected result <p></p>

Actual result </p>

Change History (4)

#1 @justinbusa
6 years ago

It looks like this happens in reverse for paragraph tags that have a style attribute. For example, this...

echo wpautop( '<p style="text-align:center;"></p>' );

will output... <p style="text-align:center;"> with no closing tag.

#2 @pross
6 years ago

Tested the bug as far back as WP 2.8, couldn't get anything earlier working in MAMP.

#3 @wiselyfoolish
6 years ago

Yup. This affects empty paragraphs only.

Current workaround solution is to strip empty paragraph tags from the text before running it through wpautop()


$text = '<p>First paragraph</p><p></p><p>Second Actual Paragraph</p>';
$text = preg_replace('@<p.*?></p>@', '', $text);
$text = wpautop($text);
Last edited 6 years ago by wiselyfoolish (previous) (diff)

#4 @pento
5 years ago

  • Version trunk deleted
Note: See TracTickets for help on using tickets.