Help, this is probably the best way to have control over the styling of the wp_tag_cloud …
I was looking for a way to add size based classes to my tags within the tag cloud widget. The problem here is that this solution only works when hard coded into for example a template file, but not for the tag cloud widget.
I also found this snippet to add slug classes and they beautifully work right out of the box. I simply had to place them inside the function.php file.
I was trying to get solution one to work in the same way solution number two works, but with the size based class names instead of slug names or even both. However, I can’t figure it out and need help. Thanks in advance.
try this code:
there might be more effective solutions, or a way to put it all into one regex; however it works (I am no expert in preg_replace()).
can be used at the same time as the slug class filter.
maybe a better/more simple approch is hooking in “wp_generate_tag_cloud_data” 😉
in $tag you have [id], [url], [name], [title], [slug], [real_count], [class], [font_size]
So if you want a custom class for every tag you can use something like: