Remove Empty P Tags From WordPress

Everyone loves WordPress but but developing on this platform front-end developers hate when users add in empty <p> tags! No one wants to manually go through and delete these tags, so here is a few code options to get rid of these pesky tags.

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
    
    
    1
    <span class="pln">remove_filter</span><span class="pun">(</span><span class="str">'the_content'</span><span class="pun">,</span> <span class="str">'wpautop'</span><span class="pun">);</span>
  2. Use jQuery to clean up all those empty p tags after the page has loaded
    
    
    1
    <span class="pln">$</span><span class="pun">(</span><span class="str">'p:empty'</span><span class="pun">).</span><span class="pln">remove</span><span class="pun">();</span>

 

Please check out our other posts for more tips and tricks on WordPress.