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:
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:
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.
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
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.