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.
5 Ways to Remove Unused Shortcodes
- Use plugin to remove shortcode
- Delete from database
- Hide from frontend
- Replace with another shortcode
- Manually removing shortcodes
Method 1 – Use Another Plugin
Again there exist a plugin to hide all unused shortcodes on your site. Install the plugin Hide Unwanted 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. However, the plugin will only hide the entered shortcodes from the published site. It will delete the unused shortcodes from the database permanently. It will also be not useful if you do not remember the shortcode names.
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 name. 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
This method is useful if you do not want to use a plugin or do not remember the exact name of the shortcodes. You can hide all 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' );
Replace ‘shortcode’ with the actual name your the shortcode.
Ensure that the shortcode you are hiding is not active (the plugin is uninstalled or the theme is not active) otherwise this will break your site.[
Method 4 – Search and Replace with Another Shortcode
Sometimes you may find the same set of features are available in your theme as well as in a shortcode plugin you are using. Especially this is the scenario when you switch theme that includes the features of the plugin you already have. For example, your plugin may provide a shortcode like [ plugin_divider ] and now that you can achieve this with your theme by adding [ theme_divider ].
Here you know both old and new shortcodes. Use the below query on your database to replace the old with new one:
UPDATE wp_posts SET 'post_content' = REPLACE ('post_content','[ old shortcode ]', '[ new shortcode ]');
Method 5 – Manually Removing Shortcodes from Site
Manual removal is a good idea when you used a shortcode only in few articles. In this case, you need to search the database and get the where used kind of list. Follow the below instructions in order to do a search on your database.
- Login to your hosting account and go to cPanel.
- Find and open phpMyAdmin section.
- Go to search tab and enter the shortcode you want to search in the text box.
- Select the tables you want to search or select all tables if you want to search the complete database.
- Click on the “Go” button.
- 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.
- Edit the content directly on the table or go to WordPress admin panel and edit manually using post editor to remove the shortcodes.