If your WordPress website has a lot of tags (and growing), you may probably struggle with bad looking messy list inside the WordPress tag cloud widget. But you would rather show descent number of tags instead of removing the widget, right?
This simple snippet will do a trick:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
//Register tag cloud filter callback add_filter('widget_tag_cloud_args', 'tag_widget_limit'); //Limit number of tags inside widget function tag_widget_limit($args){ //Check if taxonomy option inside widget is set to tags if(isset($args['taxonomy']) && $args['taxonomy'] == 'post_tag'){ $args['number'] = 10; //Limit number of tags } return $args; } |
That’s it! Just paste this piece of code inside your theme functions.php file.
This was amazingly helpful. Is there a way to filer tag types? My tag cloud shows tags for pages AND posts, and I want to exclude pages.
[…] Das WordPress Widgets Schlagwörter-Wolke (Tag-Cloud) hat standardmäßig keine Mengenbegrenzung der anzuzeigenden Schlagwörter. Dadurch werden Unmengen Schlagwörter in der Seitenleiste oder im Footer angezeigt. Die Möglichkeit einer Limitierung hat der folgende englischsprachigen Blog aufgezeigt. […]
Wow, this is a very good code. I appreciated this!
Thanks, glad you liked it!
Useful!
Thanks a lot.
Thanks for the tip…
Please remove ‘amp’ from code after &, it is causing syntax error…
from:
if(isset($args[‘taxonomy’]) && $args[‘taxonomy’] == ‘post_tag’){
to:
if(isset($args[‘taxonomy’]) && $args[‘taxonomy’] == ‘post_tag’){
Thanks, it seems that WP editor messed the things up. Everything should be fine now.
Thank you – added to https://www.ismycar.co.uk and it works a treat 🙂 Great job. Added it to my CHILD theme functions.php
Thank you. I’ve used this hint to rearrange my own cloud tag
https://rainbowzoom.pl/druk-na-plexi-akrylu
Thanks! Great!
https://www.freelancer.lt
thanks for you help. Awesome
Hi,
This tag works. However after doing this it shows the 20 tags alphabetically. How to show the TOP 20 tags alphabetically irrespective.
How can I do this?
Thanks! Great and easy function!
Thank you very much!
This work fine.
Newbie , how to and where to paste this snippets ?? thank you
Thanks its working well 🙂
Excellent tip. Worked beautifully for us.
Just be carefull as this won’t work with all installs. Took our site down completly. Had to ftp in and remove code to get site back up.
Hi,
It should work fine. Please check if you have properly closed PHP tags.
Working like a charm, Thank you very much
Eureka – thanks for sharing. You saved me a lot of headache. Just what I was looking for!
Amazing soultion that I can use in functions php.Thank you so much.
Thank you! Very useful.
WoooOOo Great. It’s work for me. Thank you
Thanks for sharing.
Just a question, what tags are shown? the most popular ?
Any way the choose what to show?
Yes, most popular!
It is possible to fetch different tags, but it will require some modifications in another filter hook…
Very useful function. Thanks a lot for sharing.
Many thanks! Finally was able to shorten that scary list of tags haha.
Very nice snippet – Thank you @ http://www.nuno-sarmento.com
Thank you for this code-snippet, I will implement this in the footer area of my website where I have to limt the number of tags.
This is such a basic feature for the tags widget, I find it shocking that the setting is not included by default in the native WP widget.
Good! thanks
So easy! Thx 🙂
Great code! Is there any way to add a line to show the tags randomly and from all the tags not only the number you put there? I mean show random 10 tags from all the tags in random order? so every time you reload the page show you 10 other random tags? Thanx!
It’s possible but this will require slightly different logic. However, we will consider creating that snippet as well in some of our next articles… 😉
thnks Meks,
its save my day 🙂 and i use it in my website which is i added here http://www.trendishops.com 🙂
Oh my, thanks so much – these overflowing tags have been driving us crazy for weeks now. What a solution!
Hey Josh,
Glad we have helped! You are welcome here anytime!
Thank you, worked !
Worked a treat, thank you!
This looks really cool! Thank you for sharing 🙂
I have a website where the tag cloud looks really nice with tags under, say, 20 characters in word/phrase length…is there a way to modify the code you’ve shown here to implement that sort of character limit, do you think?
That’s a good tip ,thanks for sharing boss.
WoW! You saved me, thanks for your trick. Simple but effective!
I’ve just begun showing tags on my own personal blog and was a little worried about the growing length of the list so this is a great help for me.
Thanks!
Glad that we helped!
Cheers!
Thank you!
Thnx, great and simple sollution…
Thanks guy!!! very good!
Why do you all not give everyone a clue as to where to add the code?
Hi Wayne,
We have wrote it in the last line of the post. As in most cases, you should add this code inside your functions.php file of your theme.
Cheers
Nice article ..very useful.
I searched on the net, but this code worked for my website, thanks.
Good to hear! You’re welcome 🙂
Great sharing, thanks,
Good system! I like it!