Thanks for responding esmi, but question… is this a frontend function? I don’t want to remove the shortcode from the theme, only a specific post layout. Basically I want to be able to add the shortcode to a post within the edit screen, but stop it from being displayed on the published pages.
Sounds foolish, but its a little bit easier for the novice WP user to upload images to a post as a full gallery, vs creating the gallery then deleting the shortcode or creating the gallery via the media page.
strip_shortcodes( $content ) comes close, but that strips ALL shortcode.
only a specific post layout
What do you mean by specific? A specific post id? All single posts?
I’m attempting to do it by post format.
So, assuming you’re using a format-xxx.php file, add something like:
<?php remove_shortcode('gallery');?>
to the top of that template file.
Thanks esmi, it works… but one last thing, it leaves the “[gallery]” on the page. Any suggestion on how to go about removing it??
Nevermind, got it…
functions.php
function stripGalleryShortcode($content){
return preg_replace('/\[gallery\]/', '', $content);
}
custom template
remove_shortcode('gallery');
add_filter('the_content', 'stripGalleryShortcode', 10);