How to remove broken and unused shortcodes

Updated January 17, 2024
~ minute read
How to remove broken and unused shortcodes

Content Key

Share this Post :
Get the most out of your marketing
Join over 100,000 of the most intelligent marketers in the galaxy, and receive marketing news and insights straight to your inbox.
Enter Email to Get Started:
(We will never share your information.)
Rank #1 on google with 702 pros seo - digital
Rank #1 on google with 702 pros seo

How to remove broken and unused shortcodes

When using shortcodes on your WordPress website, you can find that it makes adding redundant code across your website a whole lot easier as well as makes any changes to the shortcode apply to all instances of that shortcode all across your website. However, you may find that once you stop using a short code, there will be remnants of its existence all across your website leaving broken shortcode text in its place.

To fix that, in this article I will offer you three solutions and show you how to remove broken and unused shortcodes.

Manually Remove Shortcodes

Method number one is the most obvious and tedious way to remove them, and that is going through the entire website and removing it from the places you placed the shortcode. This method is best used only when you have a couple of instances of the shortcode website all across your website.

But however, you will find that removing these when you have way more than 10 instances of these shortcodes, can be way too much to remove so there has to be a faster solution, and lucky for you there is.

Hide Shortcodes from Users

An easy way to remove these shortcodes is to hide them by using the following code and pasting it in your functions.php file. This piece of code replaces the shortcode with an empty value:

-Place the shortcode name in as the first argument

add_shortcode( ‘add_shortcode_name_here)’, ‘__return_false’ );
NOTE: Make sure this shortcode is inactive before applying it.

Hide Shortcodes from with Regex

You also have the ability to hide all unused/broken shortcodes all across your website using this piece of code that uses regex to hide unused shortcodes all across your website. However, there are limitations with this method as they will not remove all shortcodes.

Paste this code into you funtions.php file:


add_filter(‘the_content’, ‘mte_remove_unused_shortcode’);
function mte_remove_unused_shortcode($content)
{ $pattern = mte_get_unused_shortcode_regex();
$content = preg_replace_callback( ‘/’. $pattern .‘/s’, ‘strip_shortcode_tag’, $content );
return $content;
}
function mte_get_unused_shortcode_regex() {
global $shortcode_tags;
$tagnames = array_keys($shortcode_tags);
$tagregexp = join( ‘|’, array_map(‘preg_quote’, $tagnames) );
$regex = ‘\[(\[?)’;
$regex .= “(?!$tagregexp)”;
$regex .= ‘\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)’;
return $regex;
}

Use a Plugin to remove shortcodes

You can use the plugin called “Hide Unwanted Shortcodes” to remove them which has an easy-to-use interface to do that.

All you have to do is:

  1. Search “Hide Unwanted Shortcodes” Plugin install and active
  2. Go to tool > Hide Unwanted Shortcodes > Follow instructions listed on the page

 

How to remove broken and unused shortcodes

How to remove broken and unused shortcodes

How to remove broken and unused shortcodes

How to remove broken and unused shortcodes

How to remove broken and unused shortcodes

How to remove broken and unused shortcodes

How to remove broken and unused shortcodes

How to remove broken and unused shortcodes

Leave a Reply

More Great Posts

Advertise with us
Join our advertising network to grow your business. Give us a call at (702) 904-4262
34.99 WordPress Updates | WordPress Support by 702 Pros
Sponsored
Build your Rank Ad 1 - RankLabel
Sponsored
Kyla Sloan | Kyla Estes | Client Management | Reception | Sales
Advertising with Us
Kyla SloanAdvertising Specialist
Our team has the digital and traditional marketing skills to get you in front of customers looking for your product or service.
Want to talk now? Give us a call at (702) 904-4262

Powered by OnSago

Add Your Business To the 702 Pros' Directory
Please add some general information about your business.
Want to talk now? Give us a call at (702) 904-4262

Powered by OnSago

2022 Sale

Get 20% off!

All Web Design Packages
Days
Hours
Minutes
Seconds
Want to talk now? Give us a call at (702) 904-4262

Powered by OnSago