Currently set to Index
Currently set to Follow

Get the Official WPSaviour App Now!

BlogTutorials

How to Find and Remove Unused Shortcodes From WordPress Posts

Shortcodes are good, nevertheless they are not on a regular basis the simplest approach. One downside of using a plugin or theme that depends upon shortcodes is that after you switch a theme or deactivate the plugin, they could go away behind shordcode tags in your posts which is ready to look uncommon to your readers. On this text, we’re going to current the way in which to find and take away unused shortcodes out of your WordPress posts and pages.

Are Shortcodes Unhealthy?

No, utterly not. Shortcodes aren’t harmful, nevertheless overusing them may be problematic. As an illustration, we use Compact Archives plugin which provides a shortcode and a template tag. Now we’ve the shortcode solely on our archives net web page, so if we ever deactivate that plugin, then there is just one net web page we’ve to remove the shortcode from.

Alternatively, there are plugins and themes that current shortcodes to create widespread mannequin parts like buttons, tables, columns, and so forth. Some ad management plugins moreover use shortcodes. Now if an individual has used these shortcodes in a lot of posts, then it turns into very powerful for the individual to remove the shortcode from all posts and pages.

For that reason we recommend our clients to not rely on themes or plugins which require you in order so as to add shortcodes into many posts. It’s best to on a regular basis try to find the next completely different for many who can, or contact the theme or plugin author. They might inform you a higher strategy to get the equivalent efficiency with out using too many shortcodes in posts or pages.

For these nonetheless questioning, once you’ve acquired an inactive shortcode in your web site, then it’ll look like this throughout the middile of your content material materials:

[some-random-shortcode]

With a function to remove unused shortcodes out of your posts and pages, you wish to first uncover them.

Uncover All Posts Containing a Particular Shortcode

We’re going to attempt the perfect technique to look out the shortcode inside submit content material materials. Merely copy and paste the subsequent code in a site-specific plugin or your theme’s capabilities.php file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
carry out wpb_find_shortcode($atts, $content material materials=null) {
ob_start();
extract( shortcode_atts( array(
        'uncover' => '',
    ), $atts ) );
$string = $atts['find'];
$args = array(
    's' => $string,
    );
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
        echo '<ul>';
    whereas ( $the_query->have_posts() ) {
    $the_query->the_post(); ?>
    <li><a href="<?php  the_permalink() ?>"><?php the_title(); ?></a></li>
    <?php
    }
        echo '</ul>';
} else {
        echo "Sorry no posts found";
}
wp_reset_postdata();
return ob_get_clean();
}
add_shortcode('shortcodefinder', 'wpb_find_shortcode');

On this code, we now have created a shortcode (how ironic is that?). The shortcode runs a carry out to execute a personalized WordPress Query. On this query, we’re using the default WordPress search operate to look out the shortcode after which report all posts found with that specific shortcode.

To utilize this, you wish to create a model new WordPress submit or net web page and paste this shortcode inside it:

[shortcodefinder find='myshortcode']

Trade myshortcode with the shortcode tag you may be looking out for. Save your submit or net web page as a draft after which preview it. This may imply you’ll be able to see a list of all posts containing the shortcode tag you regarded for.

The best solution to Take away Unused Shortcodes in WordPress

Sadly, the simplest approach to remove unused shortcodes out of your posts is by manually enhancing each submit containing the shortcode. Throughout the approach described above, we confirmed you the way in which to get a list of posts containing a particular shortcode. Hopefully, this may stop some time. Upon getting the report, then you’ll bear the posts one after the opposite and take away the shortcode.

Alternatively for many who don’t must go edit your posts one after the opposite, then there is a quick work spherical that can efficiently conceal the shortcode from exhibiting into your content material materials. Merely paste the subsequent code in a site-specific plugin or your theme’s capabilities.php file:

1
add_shortcode( 'shortcodetag', '__return_false' );

You’ll want to change shortcodetag with the shortcode exhibiting in your posts or the shortcode it’s essential conceal.

Primarily the code above will add the shortcode and make it current nothing. This trend your shortcode will possible be parsed as each different registered shortcode would, nevertheless with out exhibiting one thing throughout the output. If there are a selection of unused shortcodes in your posts, then you’ll reuse this code by merely altering the shortcodetag with the shortcode it’s essential conceal.

Download The WPSaviour App Now

Related posts
Beginner’s GuideBlogTips

Top 5 free payment gateway plugins for WordPress in India (2020)

Beginner’s GuideBlogTips

Best WooCommerce International Payment Gateways for WordPress in 2020

Best WordPress PluginsBlog

WordPress 5.4 Will Add Lazy-Loading to All Images

Beginner’s GuideBlog

How to Add a Preloader Animation to WordPress (Step by Step)

Sign up for our Newsletter and
stay informed

Leave a Reply

Your email address will not be published.