
As you may have noticed I recently launched a new version of Penguin Initiatives. I migrated WordPress themes in the process and unfortunately this resulted in me having to get rid of a lot of old shortcodes. As a result I discovered a few different ways to remove old WordPress shortcodes in a relatively easy fashion, so I thought I’d share what I learned.
Shortcode Removal Method #1: Search RegEx
This method is best for when you have a lot of old shortcodes that you want removed entirely from all of your posts, which are used for styling and don’t actually contain any information in them.
- Install & activate the Search RegEx WordPress Plugin
- Go to Tools > Search Regex
- Enable Regex by checking the checkbox
- To find all instances of the beginning of any shortcode and select the entirety of it, use this regular expression:Â [[shortcode.*]] – only replace the “shortcode” part with whichever shortcode tags you’re trying to remove.
- Then do the same for the ending tags of the same shortcode using this regular expression:Â [[/button.*]]
- Replace & save with nothing and those old shortcodes will be eliminated!
Shortcode Removal Method #2:Â Sublime Text 3
This method is best for when you have shortcodes with a similar pattern that you need to edit in bulk in a single page or post.
- Download & Install Sublime Text 3
- Copy & paste the HTML code for the post or page you want to remove the shortcodes from
- Select the beginning of the shortcode that you want to edit
- Hit Alt+F3 and this will allow you to edit all of the instances of the shortcode simultaneously
- Use your keyboard to select and edit all the instances of the shortcode that you want to edit
- Copy & paste the edited HTML code back into your post or page and save your changes
Shortcode Removal Method #3:Â Hide Broken Shortcodes
This is the quick & dirty method, because it doesn’t actually remove the shortcodes. Instead it just prevents them from being rendered. I wouldn’t recommend it, but it’s an option if you feel like being lazy.
- Install & activate the Hide Broken Shortcodes WordPress Plugin
- That’s it, it prevents non-functioning shortcodes from appearing in the content of a post or page
If you know of any other good methods for removing old WordPress shortcodes, please share them in the comments!
Nice article.
If you have access to a phpMyAdmin environment or mysql shell, you also can perform search&replace directly in the database. Don’t forget to make a backup first 🙂 I used this to delete some old shortcodes:
UPDATE wp_posts SET post_content = REPLACE(post_content, ‘[old_shortcode]’, ‘[new_shortcode]’);
If appropriate, do the same for the end shortcode code [/old_shortcode]. Unfortunately, regular expressions (REGEXP) are extremely difficult with MySQL and, afaik, cannot be combined with UPDATE/REPLACE.
For an old [image] shortcode, which I hadn’t removed, I added a new shortcode in my functions.php, to rewrite that old one into the HTML img tag:
function image( $atts, $content = null ) {
return ”;
}
add_shortcode(‘image’, ‘image’);
Those methods work too, thanks Jan!
I wish Search RegEx worked on pages so we could take advantage of the regular expressions for mass updating pages too! No idea why it doesn’t support pages, maybe one day…
Went through the source quickly (it’s too damn hot) and search-regex/searches/post_content.php does query post_type ‘page’. That should make it possible to mass update pages, right? I’m not familiar with the plugin.
Yeah you’re right, I actually just used it for something unrelated and noticed that it does indeed work on pages =)
For some reason it says Source: Post Content, but that actually includes pages too. Guess they should just adjust that label to make it a bit more clear.
Thanks for the great information! I will keep these things in mind for when I have customers in this situation.
Your article highlights at least one reason for developers to not put shortcodes in themes. We started going down the path of building a theme for sale on ThemeForest. Envato changed their rules and we had to remove all the shortcodes. If the shortcodes are in the theme, a lot of hoops need to be jumped through to switch themes.
It was a lot of work but has been best for our clients. We ended up putting the plugin (Intense WordPress Site Builder) on CodeCanyon for sale and it is doing very well. It now has 94 shortcodes, around 15 custom post types and more. We are working on the theme again and it has helped to keep the theme code clean.
I’m curious if you ran into situations where you also had to update shortcode attributes. I could see how the redex tool would fall short in fixing these problems. Did you find a good way to address this issue?
Hello Andy,
thank you for everything that you write in your site,its help new WordPress beginner, like me. and related to the subject above I would ask for your advise, I notice,maybe I’m wrong, that when I Install a themes or some plugins then delete it, the effect of those plugin or themes frameworks,keep affecting on other themes installation! so, if I was right , is there anyway to remove/delete the traces of deleted plugins of themes framework?
Hi Andy,
Thanks for the great information. All methods are easy to use and anyone can use these methods to remove shortcodes.