Sometimes we have many tags in our website and when we use “Cloud tag widget” it look very awful at our site, Then we think that might be it is possible to limit the number of tags in our WordPress tag cloud widget? Now the answer is yes, In this post i will tell you to limit number of tags.
What are WordPress tags?
Tags are used to define the type of that particular post. It defines what content is written in that post. User can click on any particular tag and they can see similar posts related to that tags,
It is not mandatory to write tags for each post. Its completely optional whether you want tags or not.
Tags can be visible in two places, One is using widget in your widget section and another is below the post. So here i am going to explain you to manage tags in both the situation.

This is a tag cloud widget it will be shown in footer and sidebar
Limit tags in tag cloud widget
- Open your themes ‘functions.php’ file from “Appearance > Theme Editor”
- Paste this code at the end of functions.php file
- After that update your changes
function prefix_widget_tag_cloud_args( $args ) {
$args['number'] = 5;
return $args;
}
add_filter( 'widget_tag_cloud_args', 'prefix_widget_tag_cloud_args', 10, 1 );
Here number of tags are ‘5’ as you can see in code. It’s totally your choice how much tags do you want to show. So you can change that value and save it again. After that refresh your page and see the result. Please check the below image for reference

Limit tags in single post
- Open your themes ‘functions.php’ file from “Appearance > Theme Editor”
- Paste this code at the end of functions.php file
- After that update your changes
add_filter('term_links-post_tag','limit_to_five_tags');
function limit_to_five_tags($terms) {
return array_slice($terms,0,5,true);
}
Here default value for tags are ‘5’. You can change this value according to requirement. In place of 5 add your value and save the file again. Now you can see the result by refreshing your page. Please check the image for reference.

Note: I recommend you to first create child theme and then try this solution in that.
So here is the complete tutorial to limit Hope this post helps you to manage tags, If you have any query related to this post then feel free to send a comment below, I will reply you back
Read More –
Hi
‘Limit tags in tag cloud widget’ works perfect. THX
This didn’t work for as of April 2021, so I used this CSS method, which did the job, in case helps anyone else:
.tagcloud a:nth-child(n+10) {
display: none;
}
Do You know how edit this code to get random tags? With this code tags is showing alphabetic.
However, thank You so much for this solution!
Absolutely brilliant dcdev!! Thanks for saving my ass with this sweet and neat piece of css. I had the problem that my page was showing two different tagclouds, one in the footer and one in the sidebar of the blog (don’t ask why). The footer one was the classic wp one and not styled, and the sidebar one i transformed into buttons but needed to limit them to ten.
After a half day of headages and different php trials this sweet line of css is THE savoiur. Thank you!!! 🙂