Limit the number of tags in your WordPress tag cloud widget

If your WordPress-powered site has a lot of tags (and growing), you will probably be struggling with a messy-looking list inside the tag cloud widget. But you would rather show a decent number of tags instead of removing the widget altogether, right?

Place the following code in your theme’s functions.php file which should resolve this issue.

//Register tag cloud filter callback
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;
}

Let us know whether this works out for you just fine!

One thought on “Limit the number of tags in your WordPress tag cloud widget

Leave a Reply