停止WordPress自动显示< p>< / p>标签 [英] Stop WordPress automatically showing <p></p> tags

查看:131
本文介绍了停止WordPress自动显示< p>< / p>标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Wordpress会在每个地方自动生成许多不需要的< p>< / p> 标签。即使 img 标记也会包裹这些< p> 标记。所以它在网站中创建不需要的空白。我尝试了很多方法删除这些标签: -

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?

推荐答案

Wordpress Visual Editor自己为新行创建这些标签。

Wordpress Visual Editor itself create those tags for new lines.

您可以尝试删除过滤器 wpautop 来自 the_excerpt the_content

You can try to remove the filter wpautop from the_excerpt or the_content

remove_filter( 'the_content', 'wpautop' );
// OR
remove_filter( 'the_excerpt', 'wpautop' );

有时它不工作(过去没有为我工作, 。

Sometimes it doesn't work (Didn't work for me in the past. Not with PHP).

您可以尝试使用Javascript / jQuery,将此代码放在DOM加载之后或关闭之前< / body> tag。

You can try with Javascript/jQuery, place this code after DOM loaded or before the closing </body> tag.

jQuery('p:empty').remove();

将删除所有空< p>< / p& code>元素。

Will remove all empty <p></p> elements from all over the document.

这篇关于停止WordPress自动显示&lt; p&gt;&lt; / p&gt;标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆