我似乎无法阻止 WordPress 自动向我输入的每一行添加段落,包括短代码和我输入到视觉编辑器中的任何原始 HTML。我尝试过使用插件“Toggle wpautop”和“Raw html”来尝试转换它,但它从来没有工作过。是因为我使用的是视觉 Composer 吗?它只是将 p 标签包裹在任何东西上。
最佳答案
问题不在于 Visual Composer,它的发生纯粹是因为 autop
过滤 the_content
。有几种方法可以解决这个问题,但恕我直言,内容过滤器是最好的处理方法。
如果您愿意编辑functions.php,您可以过滤the_content
钩子(Hook)移除<p>
包含 strtr
的短代码标签添加以下内容:
add_filter('the_content', 'remove_unneeded_silly_p_tags_from_shortcodes');
function remove_unneeded_silly_p_tags_from_shortcodes($the_content){
$array = array (
'<p>[' => '[', //replace "<p>[" with "["
']</p>' => ']', //replace "]</p>" with "]"
']<br />' => ']' //replace "]<br />" with "]"
);
$the_content = strtr($the_content, $array); //replaces instances of the keys in the array with their values
return $the_content;
}
其他替代方案( like removing autop from the_content )往往会产生相当深远的影响,所以我倾向于避免这种情况。您还可以尝试从添加的特定段落标签中删除边距样式,但由于自动添加,可能很难定位该特定标签...
关于php - WordPress 不断向短代码和内容添加自动段落标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51316972/