Ways To Remove Old WordPress Shortcodes

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

Remove Old WordPress Shortcodes with 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.

  1. Install & activate the Search RegEx WordPress Plugin
  2. Go to Tools > Search Regex
  3. Enable Regex by checking the checkbox
  4. 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.
  5. Then do the same for the ending tags of the same shortcode using this regular expression: [[/button.*]]
  6. Replace & save with nothing and those old shortcodes will be eliminated!

Shortcode Removal Method #2: Sublime Text 3

Remove Old WordPress Shortcodes with 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.

  1. Download & Install Sublime Text 3
  2. Copy & paste the HTML code for the post or page you want to remove the shortcodes from
  3. Select the beginning of the shortcode that you want to edit
  4. Hit Alt+F3 and this will allow you to edit all of the instances of the shortcode simultaneously
  5. Use your keyboard to select and edit all the instances of the shortcode that you want to edit
  6. Copy & paste the edited HTML code back into your post or page and save your changes

Shortcode Removal Method #3: Hide Broken Shortcodes

Remove Old WordPress Shortcodes with 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.

  1. Install & activate the Hide Broken Shortcodes WordPress Plugin
  2. 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!

7 COMMENTS

  1. 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’);

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

  3. 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?

  4. 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?

LEAVE A REPLY

Please enter your comment!
Please enter your name here