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;
}
Search Knowledge Base Articles
How to remove broken and unused Shortcodes
To remove any broken and unused shortcodes, paste the following code into your function.php file
Did you find this article useful?
Related Articles
-
How to get Global Options Fields using PHP
//Use get_option() to get global field //metakey is the field you want to get echo get_option('metakey');...