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('');
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);
I know this is a relative old question, but the strip_shortcodes function does work!
Easiest way if you ask me..
Strange. remove_shortcode (codex link) doesn’t take a second argument.
You’re returning either the true or false return of the remove_shortcode function, not the content with the shortcode removed.
Try either something like this in that second version of your function up there:
Or just put
In your functions.php file. The previous poster suggested including the [ ]’s, which I guess is wrong.
I think you should use sub string replacement like this:
Bear in mind, this method does not come with good performance.
update: You can unregister the shotcode in function.php by adding code:
An old question, but after some digging and a combination of answers this worked for me:
I was only inserting galleries, which I wanted to remove and display separately. Obviously if you want to remove a specific shortcode this might not be the solution for you.