Limit the number of tags in WordPress Tag Cloud widget

As a feature of the early Web 2.0, tag cloud has become very popular part of new websites. Tag cloud is a visual representation of keyword metadata, aka tags, where the most frequently user words are usually displayed in a bigger font or in a different color which would accentuate that word. The cloud looks like a little map which can instantly tell a visitor what are the most common topics around your site and navigate them directly to articles of interest.

Although a tag cloud can look great and can help a lot, if you’re using too many different tags, your cloud will look very crowded. Not only that will look messy, but some important tags might get lost in the crowd because of that.

So, you’re probably wondering how to limit the maximum tag number in WordPress. We showed you how to limit number of tags your authors can use per post. Since there is no a simple option in WordPress dashboard or settings area for limiting tags in Tag Cloud, you will have to make one for yourself. Yes, you will have to copy and paste few lines of code, but the job is done in a few seconds.

  1. Open function.php file of a theme you’re using
  2. Copy and paste the following code:
  3. add_filter('widget_tag_cloud_args', 'limit_tag_in_tag_cloud_widget');
    
    function limit_tag_in_tag_cloud_widget($args){
    if(isset($args['taxonomy']) && $args['taxonomy'] == 'post_tag'){
    $args['number'] = 10; //Limit number of tags
    }
    
    return $args;
    }
  4. In line #5, change number to any number of tags you want in a cloud.
  5. Save changes

That’s all. You can now add a Tag Cloud widget which should display no more than the number of tags you have specified in the code. Enjoy!

START YOUR OWN BLOG

This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

One thought on “Limit the number of tags in WordPress Tag Cloud widget

Leave a Reply

Your email address will not be published. Required fields are marked *