Wordpress automatically generate lot of unwanted <p></p>
tags every where. Even the img
tag also wrap by these <p>
tags. So It's create unwanted white spaces in the site. I tried lot of ways to remove those tags:-
preg_replace(array('<p>','</p>'),array('',''),the_content(),1);
remove_filter( 'the_content', 'wpautop' );
preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content)
nothing works for me. First I want to know why those tags automatically generating? And How can I fix that?
you can try this plugin
or else user this in theme's functions.php file
You need to run the
remove_filter
function in theafter_setup_theme
hook. The reason been is that it might get overrun by later on by the content or excerpt. So you would use the function as followWordpress Visual Editor itself create those tags for new lines.
You can try to remove the filter
wpautop
fromthe_excerpt
orthe_content
Sometimes it doesn't work (Didn't work for me in the past. Not with PHP).
You can try with Javascript/jQuery, place this code after DOM loaded or before the closing
</body>
tag.Will remove all empty
<p></p>
elements from all over the document.I guess this will work fine-
There are lots of plugin to disable autop in WordPress or you can use following filter to remove autop:
However, if you need to style and format content from wp-editor, you will not be able to do so if you have removed autop.
If you want to continue using autop functionality but want to remove empty p tag you can do it using jQuery.
I am able to remove unwanted empty p tags using following codes:
Go into the theme editing area of WP admin.
Add this code to your functions.php file, and save it.
OR
and place this directly above:
it should look like this: