Usually I’d just call the wp_tag_cloud() function manually from a WordPress theme file, but I have a client who wants to use the Tag Cloud Widget on their site. The tag cloud widget has been in WordPress since WP 2.3. Unfortunately, it isn’t the easiest widget to use because you can’t customize it from the backend.
Luckily there are two filters that can be used to set the arguments your client needs and maintain the ability for them to modify the widget location from the WordPress backend.
- widget_tag_cloud_args – lets you set the wp_tag_cloud arguments
- wp_tag_cloud – lets you edit the wp_tag_cloud output
So, for my clients need’s, I just needed to set the small and large font size arguments and change the widget output a little to fit their sidebar properly. I added these lines to the theme’s function.php:
1 2 3 4 5 6 7 8 9 10 11 |
function tag_cloud_args() { $args = array( 'smallest' => 8, 'largest' => 14 ); return $args; } add_filter('widget_tag_cloud_args', 'tag_cloud_args'); function tag_cloud($return) { $return = "<div class="box menu tags">" . $return . "</div>"; return $return; } add_filter('wp_tag_cloud', 'tag_cloud'); |
As with any function in WordPress, be sure to check out the codex for all the Tag Cloud Arguments that you can use.