How to Remove Unused Shortcode From Posts [WordPress]

In WordPress, if you have used plenty of plugins, you will surely come across a few that require you to put a shortcode in the post, like [shortcode_1], for it to work. Using shortcode may be a good way to add functionality to your site, but when you deactivate the plugin, the shortcode in your content don’t get removed and it will appear in the frontend in its unprocessed form.

This is how it looks like in its unprocessed form:

shortcode-not-rendered

There are several ways to remove unused shortcode from your site:

1. Remove the shortcode from database

If you know which particular shortcode you want to remove and you want to remove it permanently from your database, you can simply do a SQL query with the command below:

UPDATE wp_post SET post_content = replace(post_content, '[shortcodename]', '' ) ;

Replace “shortcodename” with the shortcode you want to remove.

Note: This is not a foolproof method because different shortcodes can come with different attributes and value, making it hard to form a catch-all SQL query.

2. Replace the shortcode with empty value

If you know which shortcode to remove, but you don’t wish to remove it permanently, you can get it to render an empty value instead. Paste the following code at the end of the functions.php file (before the ?> tag) in your theme folder.

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

Replace the “shorcodename” with the shortcode that you want to remove.

Note: This is a good method only if you know which shortcode you are going to remove. You also have to make sure that the shortcode is no longer active, else it might results in conflict.

3. Remove all unused shortcodes from content (Recommended)

If you have a bunch of shortcodes that you no longer used and you can’t remember all the shortcode name, here is an ultimate way to disable all unused shortcode in your content.

Paste the code to the end of your functions.php just before the ?> tag.

add_filter('the_content', 'mte_remove_unused_shortcode');
function mte_remove_unused_shortcode($content)
{	$pattern = mte_get_unused_shortcode_regex();
	$content = preg_replace_callback( '/'. $pattern .'/s', 'strip_shortcode_tag', $content );
	return $content;	
}

function mte_get_unused_shortcode_regex() {
	global $shortcode_tags;
	$tagnames = array_keys($shortcode_tags);
	$tagregexp = join( '|', array_map('preg_quote', $tagnames) );
	$regex = '\\[(\\[?)';
	$regex .= "(?!$tagregexp)";
	$regex .= '\\b([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*+(?:\\[(?!\\/\\2\\])[^\\[]*+)*+)\\[\\/\\2\\])?)(\\]?)';
	return $regex; 
}

What the above code does is to first retrieve the list of all active shortcodes, search the content for shortcodes that don’t match the active shortcode list and remove the shortcodes. It is modified from the get_shortcode_regex function that check for active shortcode.

Note: This method should work for all unused shortcode and it doesn’t remove the shortcode permanently. Next time you re-activate the plugin, its respective shortcode will continue to work automatically. On the flip side, this code will remove all content that are quoted between a “[” and “]” tag.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Damien Oh Avatar

Read next

Content and cloud networks now account for three-quarters of used international bandwidth, while Google, Meta, Microsoft and Amazon own, co-own or buy capacity on a growing share of the 600-plus submarine cable systems carrying over 99 per cent of data between countries, a private map hidden below the wireless internet
Wi-Fi doesn’t actually slow down when a café gets crowded — the signal is fine, but every device has to wait its turn to speak on the same frequency, and the polite queuing is what you feel as lag
In 1988, a 23-year-old Cornell graduate student named Robert Morris released a self-replicating program to measure the size of the internet — within hours it had crashed roughly 6,000 of the 60,000 machines then online, and computer security became a field
In July 2026, Psy’s Gangnam Style passed six billion YouTube views, fourteen years after its horse-riding dance became the platform’s first billion-view video and long after engineers had replaced a counter designed to stop at 2,147,483,647
Suzanne Simard sealed paper birch and Douglas fir seedlings inside plastic bags, fed them carbon-14 and carbon-13 dioxide, and nine days later found carbon had crossed between species through fungal threads in the British Columbia soil beneath her boots
A species of jellyfish called Turritopsis dohrnii can revert its adult cells back to a juvenile polyp stage when injured or starving, effectively restarting its life cycle, and biologists have so far failed to identify any natural limit to how many times it can do this.
A Japanese man named Jiroemon Kimura, who lived to 116, was born in 1897 when Queen Victoria still ruled and died in 2013, meaning a single human life personally overlapped with the invention of the airplane, the atomic bomb, the internet, and Instagram
The Hollywood sign originally read HOLLYWOODLAND when it was built in 1923 as a real estate advertisement for a housing development, and it was only meant to stand for 18 months, but nobody ever got around to taking it down and the city eventually adopted it as a landmark