要仅删除库短代码,请注册一个返回空字符串的回调函数:
add_shortcode('gallery', '__return_false');
但这只适用于回调.要静态地执行此操作,您可以暂时更改wordpress的全局状态以欺骗它:
/**
* @param string $code name of the shortcode
* @param string $content
* @return string content with shortcode striped
*/
function strip_shortcode($code, $content)
{
global $shortcode_tags;
$stack = $shortcode_tags;
$shortcode_tags = array($code => 1);
$content = strip_shortcodes($content);
$shortcode_tags = $stack;
return $content;
}
用法:
$content = strip_shortcode('gallery', $content);