Created
January 11, 2017 05:55
-
-
Save sudipbd/e5e1d0817f975d2c02f6245f97553e09 to your computer and use it in GitHub Desktop.
WordPress remove empty <p>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Remove empty paragraphs created by wpautop() | |
* @author Ryan Hamilton | |
* @link https://gist.github.com/Fantikerz/5557617 | |
*/ | |
function remove_empty_p( $content ) { | |
$content = force_balance_tags( $content ); | |
$content = preg_replace( '#<p>\s*+(<br\s*/*>)?\s*</p>#i', '', $content ); | |
$content = preg_replace( '~\s?<p>(\s| )+</p>\s?~', '', $content ); | |
return $content; | |
} | |
add_filter('the_content', 'remove_empty_p', 20, 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment