[wp-trac] [WordPress Trac] #63148: wpautop() formatting function generate invalid HTML if the text end with an empty <p> tag

WordPress Trac noreply at wordpress.org
Sat Mar 22 15:08:41 UTC 2025


#63148: wpautop() formatting function generate invalid HTML if the text end with an
empty <p> tag
--------------------------+-----------------------------
 Reporter:  gillesdoge    |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Formatting    |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 It's probably my first ticket (hi there 👋 !).

 When preparing a migration of an old WordPress, I was facing the following
 issue:

 {{{#!php
 <?php

 $text = "<p>test</p>
 <p></p>";

 var_dump(wpautop($text);
 // Output: string(16) "<p>test</p></p>
 // "
 }}}


 You may ask, but why do you need to apply `wpautop()` on an already
 formatted text?
 Because some of the content needed it (paragraphs only separated by
 newlines) and some was already formatted with HTML and Classic Editor.

 My current countermeasure is to test if the content already have `<p>` and
 don't apply `wpautop()`.


 Is this a know issue (I found nothing when searching) ?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63148>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list