diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index 8c77d167a432c..e36fb21611d09 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -591,6 +591,15 @@ function wpautop( $text, $br = true ) { $text = preg_replace( '!
(\s*]*>)!', '$1', $text ); $text = preg_replace( "|\n

$|", '

', $text ); + // If two closing paragraph tags are adjacent, remove the second. + $text = preg_replace( '|

\s*

|', '

', $text ); + + // If a block element is followed by a closing paragraph tag, remove it. + $text = preg_replace( '!(]*>)\s*

!', '$1', $text ); + + // Remove empty paragraphs. + $text = preg_replace( '|

\s*

|', '', $text ); + // Replace placeholder
 tags with their original content.
 	if ( ! empty( $pre_tags ) ) {
 		$text = str_replace( array_keys( $pre_tags ), array_values( $pre_tags ), $text );