Simple function to remove empty paragraphs in wordpress, easy way to remove empty paragraphs in wordpress without plugin.

Remove Empty Paragraphs

Using the_content filter, we will remove empty paragraph in wordpress easily and without plugin.


Copy function code and paste it in your functions.php file, function code:

function WPTime_remove_empty_paragraphs($content){
    $filter = array("/(<p>\s*<\/p>)/", "/(<p>&nbsp;<\/p>)/", "/(<p><\/p>)/"); // empty paragraph regex
    $replace = preg_replace($filter, '', $content); // remove empty paragraph
    return $replace; // return clean content
add_filter('the_content', 'WPTime_remove_empty_paragraphs');


Also <p>&nbsp;</p> will be removed.