Wordpress从内容中删除短代码

Cyb*_*kie 3 wordpress function filter shortcode

是否可以在the_content()执行之前从内容中删除图库短代码?我搜索了codex remove_shortcode( $tag )但发现它们没有显示任何例子.

我尝试添加功能

function remove_gallery($content) {
    $content .= remove_shortcode('[gallery]');
    return $content;
}
add_filter( 'the_content', 'remove_gallery', 6); 
Run Code Online (Sandbox Code Playgroud)

它不起作用..

更新:

我能够使用下面的代码取消注册短代码,但它也删除了内容

function remove_gallery($content) {
    return remove_shortcode('gallery', $content);
}
add_filter( 'the_content', 'remove_gallery', 6); 
Run Code Online (Sandbox Code Playgroud)

小智 6

我知道这是一个相对古老的问题,但strip_shortcodes函数确实有效!

global $post;
echo strip_shortcodes($post->post_content);
Run Code Online (Sandbox Code Playgroud)

如果你问我最简单的方法..


小智 5

奇怪.remove_shortcode(codex link)不接受第二个参数.

您将返回remove_shortcode函数的true或false返回,而不是删除短代码的内容.

在那个函数的第二个版本中试试这样的东西:

remove_shortcode('gallery');
return $content;
Run Code Online (Sandbox Code Playgroud)

或者只是把

 remove_shortcode('gallery');
Run Code Online (Sandbox Code Playgroud)

在你的functions.php文件中.之前的海报建议包括[],我猜错了.