Make WordPress Core

Opened 10 years ago

Closed 7 years ago

#40135 closed defect (bug) (duplicate)

wpautop adds a extra </p>

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

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>
<div>Something</div>
</div>

Attachments (2)

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

Download all attachments as: .zip

Change History (8)

#1 @SergeyBiryukov
10 years ago

  • Component GeneralImport
  • Description modified (diff)

#3 @ocean90
9 years ago

  • Component ImportFormatting

@ayubi
9 years ago

#4 @ayubi
9 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

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

/wp-includes/formatting.php

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

@ayubi
9 years ago

New Regex (preg_replace) -> line 567

#5 @ayubi
9 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 9 years ago by ayubi (previous) (diff)

#6 @pento
7 years ago

  • Keywords 2nd-opinion removed
  • Milestone Awaiting Review
  • Resolutionduplicate
  • Status newclosed

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

Note: See TracTickets for help on using tickets.