从wordpress html小部件中删除自动top



当我把它放在html小部件块中时,我在html代码中得到了不想要的

标记。我试了下面的方法,但似乎都不起作用。

remove_filter('the_content', 'wpautop');
remove_filter('the_excerpt', 'wpautop');
remove_filter('widget_text_content', 'wpautop');
remove_filter('widget_custom_html_content', 'wpautop');

我在html小部件框

中输入了这段html代码
<img href="test.jpg">
<span>text</span>
<script>alert("message");</script>

在保存小部件后,我得到下面的代码。(有一些"&;p&&;","br"(不需要的标签)

<p><img href="test.jpg"><br>
<span>text</span><br>
<script>alert("message");</script></p>

(请点击查看附件截图)截图

请帮忙吗?谢谢!

<p>是自动生成的html CC_2标签围绕wordpress内容。如果remove_filter"如果解决方案不适合您,那么您可以尝试这样做:

add_filter('widget_text_content', 'your_theme_removing_autop', 999);
add_filter('widget_custom_html_content', 'your_theme_removing_autop', 999);
function your_theme_removing_autop($content)
{
$content = str_replace(['<p>', '</p>'], ['', ''], $content);
return $content;
}

经过测试,在我这端有效。如果你也能让它工作,请告诉我!

最新更新