Categories
How-to Tricks Wordpress

Remove unused shortcodes from post content


If you have installed some plugin that adds shortcodes like [shortcode id=1] (for example [nggallery id=4], [tweeetmeme id=4 section=Name] etc), one you remove that, this pieces of text will appear in your post content unprocessed (just appear like they are in backend). WordPress has it’s own Shortcode API, so managing them is very easy. So if you don’t plan to use it or just temporary disable, you can use a pretty simple function that you can add to any plugin or theme’s functions.php that removes any shortcode you want from post output:

add_shortcode('shorcodename', 'my_remove_shortcode');
function my_remove_shortcode(){
	return '';
}

Here shortcodename is any shortcode name you want to remove, for example for Next Gen Gallery is nggallery (example shortcode [nggallery id=1])

If you need to remove more shortcodes, just add more add_shortcode lines with your shortcode like this:

add_shortcode('shorcodename', 'my_remove_shortcode');
add_shortcode('nggallery', 'my_remove_shortcode');
function my_remove_shortcode(){
	return '';
}

4 replies on “Remove unused shortcodes from post content”

This bit of code was very nice and quite handy, it don’t delete the shortcodes, witch is good if you activate the plugin, or whatever gives the shortcode, again. But most important, it removes it from the text. Thanks!

That’s the point! If you don’t want to search/replace that in DB, you may remove that annoying shortcodes from output by adding:

add_shortcode('singlepic', create_function('','return ""'));

into functions.php.

Thanks for sharing this, Vadym. Following removal of a plugin, I needed to “nullify” a shortcode which was on every post! I put your php code into a child theme; your code worked perfectly.

I like the idea of leaving the shortcode in my posts temporarily, in case I change my mind and decide that I still need to use the shortcode.

Leave a Reply

Your email address will not be published. Required fields are marked *