Tuesday, November 24, 2020
Home Blogging How to Find and Remove Unused Shortcodes From WordPress Posts

How to Find and Remove Unused Shortcodes From WordPress Posts

Shortcodes are nice, however they don’t seem to be at all times the easiest way. One drawback of utilizing a plugin or theme that depends on shortcodes is that whenever you change a theme or deactivate the plugin, they are going to depart behind shordcode tags in your posts which can look unusual to your readers. On this article, we’ll present the way to discover and take away unused shortcodes out of your WordPress posts and pages.

Are Shortcodes Dangerous?

No, completely not. Shortcodes usually are not unhealthy, however overusing them might be problematic. For instance, we use Compact Archives plugin which gives a shortcode and a template tag. We’ve the shortcode solely on our archives web page, so if we ever deactivate that plugin, then there is only one web page we have to take away the shortcode from.

Then again, there are plugins and themes that present shortcodes to create frequent model parts like buttons, tables, columns, and many others. Some advert administration plugins additionally use shortcodes. Now if a person has used these shortcodes in lots of posts, then it turns into very troublesome for the person to take away the shortcode from all posts and pages.

Because of this we suggest our customers to not depend on themes or plugins which require you so as to add shortcodes into many posts. It is best to at all times attempt to discover a higher various in the event you can, or contact the theme or plugin creator. They may let you know a greater method to get the identical performance with out utilizing too many shortcodes in posts or pages.

For these nonetheless questioning, when you have an inactive shortcode in your web site, then it would appear like this within the middile of your content material:

[some-random-shortcode]

As a way to take away unused shortcodes out of your posts and pages, that you must first discover them.

Discover All Posts Containing a Specific Shortcode

We are going to attempt the only method to search out the shortcode inside submit content material. Merely copy and paste the next code in a site-specific plugin or your theme’s features.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
function wpb_find_shortcode($atts, $content=null) {
ob_start();
extract( shortcode_atts( array(
        'find' => '',
    ), $atts ) );
$string = $atts['find'];
$args = array(
    's' => $string,
    );
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
        echo '<ul>';
    while ( $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 operate to execute a customized WordPress Question. On this question, we’re utilizing the default WordPress search characteristic to search out the shortcode after which listing all posts discovered with that particular shortcode.

To make use of this, that you must create a brand new WordPress submit or web page and paste this shortcode inside it:

[shortcodefinder find='myshortcode']

Exchange myshortcode with the shortcode tag you’re on the lookout for. Save your submit or web page as a draft after which preview it. This can assist you to see a listing of all posts containing the shortcode tag you looked for.

You May Also Like : How to Add Custom Shortcut Links to WordPress Toolbar

Easy methods to Take away Unused Shortcodes in WordPress

Sadly, the easiest way to take away unused shortcodes out of your posts is by manually modifying every submit containing the shortcode. Within the technique described above, we confirmed you the way to get a listing of posts containing a specific shortcode. Hopefully, it will prevent a while. Upon getting the listing, then you’ll be able to undergo the posts one after the other and take away the shortcode.

Alternatively in the event you don’t wish to go edit your posts one after the other, then there’s a fast work round that may successfully conceal the shortcode from showing into your content material. Merely paste the next code in a site-specific plugin or your theme’s features.php file:

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

You would want to switch shortcodetag with the shortcode showing in your posts or the shortcode you wish to conceal.

Mainly the code above will add the shortcode and make it present nothing. This manner your shortcode will likely be parsed as another registered shortcode would, however with out exhibiting something within the output. If there are a number of unused shortcodes in your posts, then you’ll be able to reuse this code by simply changing the shortcodetag with the shortcode you wish to conceal.

We hope this text helped you discover and take away unused shortcodes out of your WordPress posts or pages. For questions and suggestions please depart a remark under.

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

24 Best Online Jobs from Home Without Investment

Do you already know online jobs and work from dwelling jobs have gotten a scorching development after Covid-19. Earlier there have been a handful...

Top 25 Data Entry Jobs from Home Online/Offline: No Investment

Data Entry jobs are actually nice for individuals who need to work from house however not a lot certified. Whether you're a housewife, a...

What is the average salary in India?

Why you should learn about the average salary in India and remainder of the world. It is essential to your profession so it's a must...

Best Courses after 10th Standard

Results for 10th normal are simply being declared throughout India. As pupil or guardian, you should be fearful about greater schooling courses after 10th normal. Nowadays, there...

Recent Comments