Blog - WordPress tutorials and snippets

Limit number of tags in WordPress tag cloud widget

March 21, 2013 | 14 Comments
tags_wordpress

If your WordPress website has a lot of tags (and growing), you may probably struggle with bad looking messy list inside the WordPress tag cloud widget. But you would rather show descent number of tags instead of removing the widget, right?

This simple snippet will do a trick:

//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;
}

That’s it! Just paste this piece of code inside your theme functions.php file.

14 Comments

Speak your mind

Current day month ye@r *