Remove empty p tags from WordPress posts function wps_clear_content($content) { // clean up p tags around block elements $content = preg_replace(array( '#<p>\s*<(div|aside|section|article|header|footer)#', '#</(div|aside|section|article|header|footer)>\s*</p>#', '#</(div|aside|section|article|header|footer)>\s*<br ?/?>#', '#<(div|aside|section|article|header|footer)(.*?)>\s*</p>#', '#<p>\s*</(div|aside|section|article|header|footer)#', ), array( '<$1', '</$1>', '</$1>', '<$1$2>', '</$1', ), $content); return preg_replace('#<p>(\s| )*+(<br\s*/*>)*(\s| )*</p>#i', '', $content); } Usage add_filter('the_content', 'wps_clear_content', 20, 1);