Skip to main content

The tag cloud widget is a life saver when you want to occupy that empty space in the sidebar. However, the downside to the tag cloud widget is that the default widget does not have an option or a parameter to limit the number to tags to be displayed. However, there is a small workaround for this. Let’s take a look at how to limit the number of tags in the default tag cloud widget in WordPress.

Tag Cloud

How to Limit the number of tags in the Tag Cloud Widget in WordPress?

Read Also: WordPress Tutorial – Add a Coming Soon Page

I am sure that the number of tags in the tag cloud widget simply annoys you but with a simple snippet of code you can limit the number of tags in the default widget by WordPress. This guide involves manipulating the functions.php file of your WordPress theme. It’s recommended that you have backup your website just to make sure that nothing breaks. Follow the below mentioned steps to ensure that nothing goes wrong:

Step 1: Add the tag cloud widget to your sidebar or footer. I know this a no-brainer but it’s still worth to mention this!

tag cloud wordpress

Step 2: Open your theme functions.php. The best way to do this is simply go to your WordPress dashboard. Go to Appearance – Editor. Find the functions.php file on the right sidebar.

Theme editor WordPress

Step 3: Once you’ve opened your functions.php file. Scroll to the end and paste this code snippet below.

add_filter( 'widget_tag_cloud_args', 'rmn_tag_limit' );

function rmn_tag_limit($args){ 
	// Check if taxonomy option of the widget is set to tags
	
	if ( isset($args['taxonomy']) && $args['taxonomy'] == 'post_tag' ){
		$args['number'] = 7; // Number of tags to show
 	}
	
	return $args;
}

Step 4: Enter the number of tags you want to display in the tag cloud by setting the $args[‘number’] variable to the desired number. I would suggest using 7-10 tags depending on the layout of your theme.

tag cloud wordpress limit number

That’s it. You have successfully limited the number of tags your tag cloud displays. Please let us know if you have some troubles at any step in the comments section below and subscribe to ReadMeNow for more such articles.

Harsh Shah

Harsh Shah

A highly motivated individual with a hunger to learn and share as much as I can about everything. Masters in Interaction Design with a Bachelors in Computer Science. I have worked with clients across the globe on various design and tech projects. I believe in giving back and that's how ReadMeNow was founded.

Leave a Reply