Remove Empty Paragraphs From Content
Cleans up the empty paragraphs and stray line breaks left behind by pasted text, old page builders and shortcodes, so spacing stays even.
Opens WPIDE on
Code
add_filter( 'the_content', function ( $content ) {
$result = preg_replace( '/<p(?:\s[^>]*)?>(?:\s| | |<br\s*\/?>)*<\/p>/i', '', $content );
return null === $result ? $content : $result;
}, 20 );
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.