Stop WordPress automatically showing

tags

2019-02-13 11:02发布

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?

7条回答
看我几分像从前
2楼-- · 2019-02-13 11:58
$content = preg_replace('#^<\/p>|<p>$#', '', $content);
echo do_shortcode($content);

I tried it while using it in shortcode and it worked for me.

查看更多
登录 后发表回答