Wordpress remove shortcode from content

CyberJunkie picture CyberJunkie · Dec 17, 2011 · Viewed 17.4k times · Source

Is it possible to remove the gallery shortcode from the content before when the_content() is executed? I searched codex and found remove_shortcode( $tag ) but they show no examples.

I tried adding to functions

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

It doesnt work..

Update:

I was able to unregister the shortcode using the code below, but it also removes the content

function remove_gallery($content) {
    return remove_shortcode('gallery', $content);
}
add_filter( 'the_content', 'remove_gallery', 6); 

Answer

WordPressGuy picture WordPressGuy · Sep 28, 2012

I know this is a relative old question, but the strip_shortcodes function does work!

global $post;
echo strip_shortcodes($post->post_content);

Easiest way if you ask me..