How To Set Limit For WordPress Tag Cloud - Reduce Number Of Tags Displayed - Techubber

How to set limit for WordPress Tag Cloud – reduce number of tags displayed

Categories: ,

Like & Share:

WordPress Tag Cloud is a default widget element which you can include in your website to display a list of tags. Tags are helpful for your site visitors to explore more articles on your website which may increase visitor engagement on your site. By default, as you add more articles, the number of tags also grows. This may look bad for your site especially depending on your placement. The default number of tags for the WordPress Tag Cloud count is 45. If you want to set limit for WordPress Tag Cloud, you can do it without using any plugins.  In this post, we shall see How to set limit for WordPress Tag Cloud – reduce number of tags displayed.

How to set limit for WordPress Tag Cloud – reduce number of tags displayed

Steps to set limit for the WordPress Tag Cloud

  • Login to WordPress
  • Click on Appearance > Theme File Editor
    WordPress Theme File Editor is not visible in WordPress dashboard?
    You must be using some Firewall / Security Plugins which might have disabled the ability to edit PHP files via the WP dashboard. 
    Find your security plugin and disable it.  Or you can also change it by editing wp-config and change DISALLOW_FILE_EDIT to false.define( ‘DISALLOW_FILE_EDIT’, false );
  • Select the correct theme to edit
    If you are using a Child Theme, make sure your child theme is selected here.
  • After you have selected the theme to edit, click on THEME FUNCTIONS file (functions.php). 
    If this file is not present, you need to create one from your host file manager.
  • Copy and paste the following lines of code in the functions.php within <?php and ?>
    //Register tag cloud filter 
    add_filter('widget_tag_cloud_args', 'tag_widget_limit');
    
    //Limit number of tags inside widget
    function tag_widget_limit($args){
    
     //Check if taxonomy option inside widget is set to tags
     if(isset($args['taxonomy']) && $args['taxonomy'] == 'post_tag'){
      $args['number'] = 10; //Limit number of tags
     }
    
     return $args;
    }
  • Change the number of tags to display in the code above near ‘//Limit number of tags' as per requirement.

wordpress-theme-file-editor

Advertisement
  • Click Update File

That’s all. The number of tags in the WordPress Tag Cloud widget will now show tags as you have set in the code.

 

 

Related Posts

Like & Share:
Previous

We have removed your channel from YouTube – How to recover suspended YouTube Account

How to move the start button in Windows 11 to the left – Windows Tips

Next

Leave a Comment (FB)

Leave a comment