One of the defaults WordPress widget is tag cloud widget. This widget allows you to display list of tags or categories or any custom taxonomies in your site. Today we’re going to learn how to customize the widget.
To customize WordPress Tag Cloud widget, there is a widget_tag_cloud_args
filter available. Here’s a list of parameters accepted
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
For more info, please read it on WordPress Codex.
Limit Tag Cloud Widget to 20 items and Order by Count
1 2 3 4 5 6 7 8 9 |
|
By default, the widget will show up to 45 tags or categories and is order by name. In this example, we’re limiting the number of item to 20 and order it by count. Pretty straighforward.
Customize The Font Size of Each Item
If you notice, the font-size of each item in the widget is different. Tags or categories with higher number of articles will have a slightly bigger font size. Sometimes this looks bad. I prefer all of them to have same font size. Here’s the code to do so.
1 2 3 4 5 6 7 8 9 |
|
Notice that we set the smallest and largest parameter with the same font size. By doing this, all of the tags or categories will have the same font size.
Here’s the final result. Looks much better. Notice here that I combine the two codes above.
In the comment section below, Tom asked how to display the tag cloud exactly as shown in the image above. Here’s the CSS code. This code belongs to style.css file of your child theme.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Lahaul Seth says
I used to customize my tag clouds all the time when I was on Blogger. In wordpress, it’s different especially if you’re using Genesis and an error in php causes a lot of problem. Thanks for the tutorial.
Editor says
No, this method can be used for any WordPress theme. Since the tag cloud widget is the default WordPress widget, the code above can be used for any theme, not just for Genesis specific themes.
Chandan says
Thanks for this. Helpful for me.
Tom says
Thanks for this. Can you tell me how you get your tags to look like do in the image above? Is that a plugin? My tags are just text only but I’d like to display them in grey rectangles like you’ve done above. Thanks.
Editor says
Hi Tom,
Glad you asked that. I’ve updated the post with a code snippet. Please let me know if that helps to solve your problem.
Tom says
Yes, thanks this is exactly what I needed.
Editor says
Awesome. Glad that helped you
Steve says
Excellent! This just really got me out of a tight spot. I had a look at a few tutorials and no luck. This worked first time. Thanks very much.