【发布时间】:2012-11-10 16:47:56
【问题描述】:
寻找一种 php 函数(非 jQuery 或 wpautop 修改)方法从 wordpress 中删除 <p></p>。
我试过了,但它不起作用:
function cleanup_shortcode_fix($content) {
$array = array (
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']',
']<br>' => ']'
);
$content = strtr($content, $array);
return $content;
}
add_filter('the_content', 'cleanup_shortcode_fix');
【问题讨论】:
-
括号和标签之间的内容中是否有空格或空格(\n 等)?
-
当他的以括号开头的段落突然变成断段落时,编辑会不会感到惊讶..
-
@DamienOvereem:
has_shortcode的实现可以解决这个问题。 -
只是想指出,如果我在 add_filter 的末尾添加 10 个优先级,上述代码对我有用,例如
add_filter('the_content', 'cleanup_shortcode_fix',10,1);
标签: php wordpress function shortcode