How to Remove Unused Shortcodes from WordPress Site?
The power of self-hosted WordPress platform heavily relies on how effectively you use plugins. Besides whatsoever costly theme you have there are always plugins needed to boost certain parameters and shortcode plugins are the most popular to offer any feature which can be inserted anywhere on a site. Nowadays almost all themes themselves have built-in shortcodes encouraging users to add it anywhere on posts. The real problem comes when you want to uninstall the plugin or switch the theme because the shortcodes will not be removed automatically. This is the reason sometimes you may be seeing irrelevant text in-between content something like below:
What you see in the above picture within the square brackets […] are the shortcodes supposed to show the listed content. Since the shortcode plugin is deactivated it shows the actual shortcodes along with the content.
In this article we discuss the possible ways of removing the shortcodes from your WordPress site visibly shown to the readers.
Method 1 – Use Another Plugin
Again there exist a plugin to hide the unused shortcodes. Install the plugin hide unwanted to shortcodes, enter the shortcode list you do not want to display on a live site and the plugin will hide them from the site.
This is a quick fix if you remember the shortcode names. Remember the plugin will only hide the entered shortcodes from the published site but don’t delete them from the database permanently.
Method 2 – Delete the Shortcodes from Database
Here again you need to remember the shortcode names used on your site. Login to your hosting account and navigate to phpMyAdmin section. Select the database of your site and run the below query to delete the shortcode permanently from your WordPress database.
UPDATE wp_post SET post_content = replace(post_content, '[shortcode]', '' ) ;
Replace [ shortcode ] with your original shortcode.
Important point here is that the shortcodes will be permanently deleted from the database. In case if you want to go back to the old plugin or theme then you need to manually add the shortcodes again.
Method 3 – Hide Shortcodes from Users
Similar to method 1, if you do not want to use plugin or do not remember the exact name of the shortcode then you can hide all of the unused shortcodes from the live site by adding the below code in your functions.php file:
// Code to remove unused shortcodes from WordPress site
add_shortcode( 'shortcode', '__return_false' );
Method 4 – Search and Replace with Another Shortcode
Sometimes you may find the same set of features is available in your theme as well as in a plugin you are using. Especially this is the scenario when you switch theme which includes the features of the plugin you already have. For example, your plugin may be providing a shortcode like [ plugin_divider ] and now that you can achieve this with your theme by adding [ theme_divider ]. Here you know the old and new shortcodes and use the below query on your database to replace the old with the new one:
UPDATE wp_posts SET 'post_content' = REPLACE ('post_content','[ old shortcode ]', '[ new shortcode ]');
Method 5 – Manually Removing Shortcodes from Site
If you have used the shortcode very few places on your site then need to search the database to get the where used kind of list. To do a search on your database, login to your cPanel, navigate to phpMyAdmin section and go to search tab. Just enter the shortcode you want to search and select the table (select all if you want to search the complete database).
You will get a list of matches as below and click on the browse button to see more details.
You will see the list of the posts where the shortcode is actually used and edit the post manually from WordPress visual editor to remove the shortcode.