WordPress – Remove Empty p Tags

So you know we all love WordPress. That being said, there is a lot of things that can bug the heck out of your average developer when building sites with WordPress. For me it the dreaded wpautop function! That’s the little blighter that is responsible for creating a lot of extra line spaces in many of your WordPress posts. It might be a br tag or it might be and empty p tag. Do you want to use html comments in your WordPress post? Not without the wpautop function wrapping them in p tags and causing unsightly white space all over your page. Damn it WordPress stop messing with my markup!

How to Remove empty p tags in wordpress

So there are 2 basic choices if you want to stop wpautop from adding empty p tags

  1. Use PHP in your functions.php file to remove the wpautop filter
    remove_filter('the_content', 'wpautop');
  2. Use jQuery to clean up all those empty p tags after the page has loaded
    $('p:empty').remove();

The problem with both these methods is they are global, They will happen on every post, every page even all your custom post types. This might not be a problem for you but for me and your basic WordPress author those automatic p tags come in handy when writing simple posts or pages.

Remove empty p tags from specific pages in WordPress

If you want to kill that wpautop function on specific page, for instance when you need to just dump a big blob of custom markup in to the content field then I created a WordPress plugin that will work for you.

Simply download this plugin from the Github repo, upload and activate the plugin and it will add a checkbox to all your posts and pages. Just check that box and bam no more empty p tags on that page or post.

 

Leave a Reply

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