Skip to content

Instantly share code, notes, and snippets.

@ninnypants
Created April 6, 2012 16:33
Show Gist options
  • Save ninnypants/2321174 to your computer and use it in GitHub Desktop.
Save ninnypants/2321174 to your computer and use it in GitHub Desktop.
Clean up empty tags in the_content
<?php
add_filter('the_content', 'remove_empty_p', 20, 1);
function remove_empty_p($content){
// clean up p tags around divs
$content = str_replace(array('<p><div', '</div></p>'), array('<div', '</div>'), $content);
$content = force_balance_tags($content);
return preg_replace('#<p>\s*+(<br\s*/*>)?\s*</p>#i', '', $content);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment