How to limit the WordPress tag cloud

By default, WordPress tag cloud widget will display a big list of tags you are using on your blog, up to 45 last time we checked. Besides the fact it can affect your PageRank flow, if you use a lot of tags, that widget is going to look like a complete mess. Considering there is no option in the dashboard to limit the number of tags and you don’t want to use a plugin for that, you can easily change this by using following code.

Paste the following code in your functions.php file to set it to a limit of 10 tags. Don’t forget to make a backup first.

//Set the number of tags in the cloud widget
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; 
}
return $args;
}

Do you want to build a flawless WordPress site? 

Related Blogs

Web developer
Symfony-PHP-Developer_02
Quick question?