Shortcodes—the great time saver for many WordPress users looking to build a site or add something without the hassle of coding from scratch. Now, I love to use Shortcodes as much as the next person, but they tend to be a remedy that can lead to plenty of other problems down the road.
For example, if you used these Shortcodes via a plugin or a WordPress theme and then stop using either one, then chances are that your site is now riddled with heaps upon heaps of shortcodes that no longer translate into anything but a mess and leaving you wishing that you had selected to go with widgets instead.
If you’ve been hit with this mess and want to save yourself the time of cleaning it all up on your own, then this post is for you!
How To Remove Unused Shortcodes from WordPress
So assuming that you have quite a few shortcodes that you no longer use, then, there is a seemingly simple fix to washing your site clean of all of them.
First, login to your WP dashboard and go to Appearance → Editor.
Next, search through the links on the right side of your dashboard to find the functions.php file.
Scroll to the bottom of your functions.php file and paste the following code just before the last ?> tag there:
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; }
When you save this code here, you will be telling WordPress to find and remove all of your shortcodes. Therefore, if you’re using shortcodes in your site still, this may not be your best option. Also, the code can, on occasion, do more harm than good.
Another option to cleaning up the look of your site is by hiding these shortcodes instead of messing around with the code or your site.
The easiest way to do this is to use the Hide Unwanted Shortcodes plugin.
Download and install the plugin and then navigate to the plugin’s setting options. There you will find a screen that asks you to place the shortcode tags you wish to hide. You don’t have to enter every single unused tag here (that would take as long as removing them all yourself). Instead, simply go after the single tags that you no longer use.
For example, say you have a whole bunch of tags that look like this:
[column-3] Here’s some random information [/column]
[column-3] Content from another page [/column]
Instead of entering the whole string or sentence, you would simply enter [column-3] in the text box of the plugin’s setting area. Enter all the tags you wish to hide and then save it.
After that, your pages will look nice and sparkly clean.
Cleaning it up this way doesn’t actually get rid of the shortcodes, it only hides them, which is essentially like dusting that unsightly dirt in your living room under the carpet — not the best solution but at least your living room will look clean to everyone else.
Unless you know what you’re doing, it is generally best not to mess with the code of your functions.php file. So I suggest going with the second option of hiding the codes until you’re more comfortable with tweaking and adding code.
This is very helpful article. I was trying to remove in several times but did not.
We have been using the Schema theme for our several blogs. This is really a helpful article to remove the unessential shortcodes. I\’ll add the codes in functions.php file and follow the remaining guidelines as instructed. Thanks!
Hi Camila,
Thanks for your comment. Glad we could help!
Keep visiting 😀
Hi there, this code worked beautifully! Thank you! The only problem is that there are some closing shortcode brackets from Divi left behind on the site. https://cl.ly/3Q0g171n1x22 My php is not quite as good as it should be. Could you please tell me where I should add the additional brackets to this code? Thank you!!
Hello Sara, please try with the second method. You can remove these remaining shortcodes using Hide Unwanted Shortcodes plugin.
Thanks but I really want to remove them, not just hide them. I think it is just one extra expression that needs to be added to the code but I can\’t figure out where. I will keep looking, thanks!
Hello Sara, maybe you can open support ticket in our support forum, our support staff will help you to fix this.
Also please check this plugin https://wordpress.org/plugins/remove-orphan-shortcodes/, it will not delete the shortcode but it will remove it form the frontend source code.
Hope this helps, thank you.
What about this new plugin ( Shortcode Cleaner – Clean WordPress Content from Broken Shortcodes )
https://plugins.jozoor.com/shortcode-cleaner/
I think it will help more for that.
Regards.
Hi Mohamed,
You can try it but it is always better to do it manually for such an easy task as an excess of plugins will slow down your site.