WordPress: Delete unused shortcodes in blog posts

Many WordPress advanced users as well as plugins make use of shortcodes to add content, include certain functionalities or include some text with blog posts, among other uses. Shortcodes make it easy to add content or functionalities in WordPress, but these also have a huge disadvantage.

Once you stop using a plugin or the shortcode, you will still have it littered across blog posts and pages. This means you will have [shortcode] visible in posts and hurting the website’s aesthetics. Deleting unused shortcodes from each blog post is a long and tedious process.

You can easily delete a shortcode from blog posts by running the following query on your WordPress MySQL database. You will have to replace [shortcode] with your real shortcode (with the brackets) in the query.

UPDATE wp_post SET post_content = replace(post_content, '[shortcode]', '' ) ;

This query finds and deletes the shortcode from blog posts. You can also export the WordPress database and then find-replace the shortcode with blank (no value) using a text editor such as Notepad. This will delete all the instances of the particular shortcode. Once you have deleted all the shortcodes, drop the existing tables and import the modified SQL file.

Important: Make sure to backup your database before tinkering with it. You have been warned.