Problem of empty paragraphs in WordPress

Empty paragraphs can spoil not only the appearance a website but and steps towards regarding SEO optimization. That is why, this fix can be use for each themes.

Remove empty paragraphs from the_content()

Problem: How to remove empty paragraphs from the_content() functions

Solution: All such tasks can be resolve use filters:

<?php
// Remove Empty Paragraphs From the_content()
add_filter( 'the_content', function ( $content ) {
	$content = force_balance_tags( $content );
	return preg_replace( '/<p>(?:\s| )*?<\/p>/i', '', $content );
}, 10, 1 );

Leave Comment

2 Replies to “Remove empty paragraphs from the_content()”

Your email address will not be published. Required fields are marked *