I recently had the task of migrating a website from the Enfold WordPress theme to Beaver Builder. However, the Enfold theme left behind a mess of orphaned shortcodes scattered throughout thousands of posts, making the migration process a bit of a nightmare. If you’re familiar with WordPress shortcodes, you know how useful they can be in adding custom functionality to your website. But when shortcodes are no longer relevant or are improperly closed, they can cause major headaches for website owners and developers.

In this blog post, I’ll show you how to use regular expressions to remove orphan shortcodes from the Enfold WordPress theme or any WordPress theme with a little bit of modification to the code.

Removing orphan shortcodes can be a tedious process, but it can also improve your website’s performance and prevent errors from occurring. Luckily, with regular expressions, you can remove these orphan shortcodes in just a few simple steps.

First, open your WordPress database management tool, such as phpMyAdmin or MySQL Workbench. Then, navigate to the “wp_posts” table, which contains your website’s content.

To remove orphan shortcodes that start with “[av_” and end with a single closing bracket “]”, you can use the following query:

UPDATE wp_posts
SET post_content = REGEXP_REPLACE(post_content, ‘\\[av_[^\\]]*\\]’, ”)
WHERE post_content REGEXP ‘\\[av_[^\\]]*\\]’;

This query will find all instances of orphan shortcodes that start with “[av_” and end with a single closing bracket “]” and remove them from your website’s content.

If you want to remove orphan shortcodes that have a closing tag, such as “[/av_section]”, you can use the following query:

UPDATE wp_posts
SET post_content = REGEXP_REPLACE(post_content, ‘\\[av_[^\\]]*\\][^\\[]*\\[/av_[^\\]]*\\]’, ”)
WHERE post_content REGEXP ‘\\[av_[^\\]]*\\][^\\[]*\\[/av_[^\\]]*\\]’;

I also discovered some more questionable shortcodes on a few very old posts – I will have to investigate more but they look.. bad.  Anyway.. easily removed

UPDATE wp_posts
SET post_content = REGEXP_REPLACE(post_content, ‘<!–codes_iframe–>.*<!–/codes_iframe–>’, ”)
WHERE post_content LIKE ‘%<!–codes_iframe–>%’;

I was able to introduce chatGPT which review, enhanced and produced the correct queries required for these tasks without much issue but I would obviously advise doing a simulation and obviously taking backups of your data first.

 

FearfulSatisfiedFruitbat-max-1mb