Mass Deleting Broken Shortcodes in WordPress

First of all, get yourself the (old-but-still-works) Search Regex plugin. Don’t edit these posts by hand or you’ll want to slit your wrists within minutes. Instead, you’re going to use Regular expressions and man, does this make your life easier! Don’t worry if you’re not a reg-ex whiz. I’m not either! But I figured it out so some examples.

Shortcodes can be deleted in two swipes if you have content wrapped in them you want to keep. Let’s say you had the misfortune to be tasked with cleaning up a site that used to run Avada as it’s theme so you have a billion useless shortcodes to clean up. So you have a bunch of this:

[fusion_whatver attribute="blah,blah,kill-me-now"]This is content I still need to keep, damnit![/fusion_whatever]

Not good. But you can resolve it in literally a couple minutes.

First of all, take a backup of your database first. DUH! You can break things and I’m not going to help you try to fix them. Then get busy with your plugin.

Opening Shortcode Search

@\[fusion.*?\]@

Your search will look something like this, with your actual shortcode text of course. This is saying, give me all the shortcode starting with the word “fusion” until the shortcode closing bracket.

The @ symbol is the delimiter, starting and ending the search expression. The forward slash is an escape character, specifying that left bracket is part of what you’re looking for in the text, not search instructions.

The dot and asterisk say to grab stuff after the beginning of the shortcode text specified, and the question mark basically says not to grab too much. This will pick up all the shortcodes start with “[fusion” up to right bracket. So this is what it would match from the example above.

[fusion_whatver attribute="blah,blah,kill-me-now"]

The content you want to keep won’t be touched. Leave the replacement field blank and pull the trigger. Then move to the next part.

Ending Shortcode RegEx Search

@\[\/fusion.*?\]@

This is looking for closing fusion shortcodes. The extra forward slash is to escape the backslash so again, specifying that is part of the actual search text and not instructions. It will remove any closing shortcode tags like the “fusion_whatever” in the example without messing up the content wrapped in the shortcodes.

And if you don’t want the content in between the shortcode tags? Use the initial statement but without the question mark and it will get it all Like this:

@\[fusion.*\]@

There is a preview function so you can check and make sure you’re actually doing what you want before you hit the button that is marked “Save. “If you know Regex you could do all sorts of weird and dangerous things with this but if you don’t, maybe this will be enough to get you going. Good luck!

Bonus Points: That penguin guy has a very helpful article on this! Thanks, Penguin dude.

Share Button

Leave a Reply

Your email address will not be published. Required fields are marked *