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.

Tags cloud widget

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

Code Tags Cloud Widget

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.

Code tags post

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 –