Make WordPress Core

Opened 7 years ago

Closed 5 years ago

#40135 closed defect (bug) (duplicate)

wpautop adds a extra </p>

Reported by: jim5471's profile jim5471 Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7.3
Component: Formatting Keywords: has-patch
Focuses: Cc:

Description (last modified by SergeyBiryukov)

This is similar to bug reported here #39307

post content

<div><img src="/wp-content/uploads/example.jpg" alt="something" /><div>Something</div></div>

generated markup - note wrong </p> after <img>

<div><img src="/wp-content/uploads/example.jpg" alt="something" /></p>

Attachments (2)

formatting.php (285.8 KB) - added by ayubi 6 years ago.
formating.diff (291.5 KB) - added by ayubi 6 years ago.
New Regex (preg_replace) -> line 567

Download all attachments as: .zip

Change History (8)

#1 @SergeyBiryukov
7 years ago

  • Component changed from General to Import
  • Description modified (diff)

#3 @ocean90
6 years ago

  • Component changed from Import to Formatting

6 years ago

#4 @ayubi
6 years ago

I am new here :) really didn't know how to show the code that i have written like others!
i wrote this line of code for fixing this bug and also have tested

$pee = preg_replace('/(img\s)?(^">|<\/p>)/', "", $pee);


Last edited 6 years ago by ayubi (previous) (diff)

6 years ago

New Regex (preg_replace) -> line 567

#5 @ayubi
6 years ago

  • Keywords has-patch 2nd-opinion added

More information About test:
1- Firstly I entered some inline HTML without any whitespace including <img /> using only text mode on the editor and saved directly!
2- then i checked post source and i found that wpautop has added <p></p> after ending <img /> tag.
3- After some research added a new Regex line at /wp-includes/formatting.php and tested again with same process and Bug has been resolved

Last edited 6 years ago by ayubi (previous) (diff)

#6 @pento
5 years ago

  • Keywords 2nd-opinion removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Closing this as a duplicate of #27350, which has the same root cause.

Note: See TracTickets for help on using tickets.