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.
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!
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.
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.
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.