Sometimes when you’re updating a WordPress site by replacing the theme, you may need to remove shortcodes which were added by the old theme, perhaps by a page builder module. It can be very tedious to strip the shortcodes manually, so the simplest way is to perform a search and replace on the wp_posts table in the database.
- First, back up your database!
- It’s always advisable to use a serialised data-safe search method in WordPress databases, so download the Database Search and Replace Script from interconnect/it.
- Once you’ve placed the script on your web server, fire it up and select the “use regex” checkbox, and the multiline (“m”) and “s” parameters.
- Select the “select tables” radio, and highlight the wp_posts table (you may have a different table prefix).
- Enter the following pattern in the search field (which is labeled “replace”):
replacing shortcode_name with the name of the shortcode you wish to remove.
This pattern will find both opening and closing shortcodes, but leave any text between them, which is probably what you want.
- Click Dry Run, and carefully check the sample results to make sure it’s doing what you expected.
- Finally, when you’re ready to actually make the changes to the database, and are sure you have backed up your database, click Live Run.