Automatically remove empty paragraphs in WordPress

When using certain blog publishing methods such as posting from Microsoft Office, one may have an empty blank line between paragraphs which is interpreted by WordPress’s automatic formatting as an empty paragraph. This results in an extra empty paragraph between each paragraph of text.

To remove these empty paragraphs of whitespace automatically when publishing or updating a post, edit formatting.php in the wp-includes folder of your wordpress installation. Search for “function wpautop”. Right before the line that says “return $pee;”, insert this code:

// Remove empty paragraphs.
$pee = preg_replace("|\s*( )*\s*|", '', $pee);

Obviously a plugin would be a more permanent solution since this change will be lost upon upgrading WordPress.

Leave a Reply

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