当我用 {% filter shortcodes %} {% endfilter %} 包装我的代码时,Wordpress 会自动添加 p 标签。无论如何我可以禁用它,因为我必须使用过滤器简码代码。我正在使用 Twig 和高级自定义字段,所以 the_content 对我不起作用。
这是我在 functions.php 文件中尝试的内容:
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;
}
remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 99);
remove_filter ('acf_the_content', 'wpautop');
add_filter('acf_the_content', 'wpautop');
请帮忙!!