Ever wanted to exclude a tag from the tag cloud but there’s no option in the widget? Well in wp-includes/widgets/class-wp-widget-tag-cloud.php there is a filter called widget_tag_cloud_args you can use.
add_filter( 'widget_tag_cloud_args', 'jmw_exclude_tag_from_tag_cloud');
function jmw_exclude_tag_from_tag_cloud( $args ) {
$args[ 'exclude' ] = '36'; // ID of the tag. If multiple tags use comma delimited sting '2,5,36'
return $args;
}
/*
* Other arguments that can be changed
* 'smallest' => 8,
* 'largest' => 22,
* 'unit' => 'pt',
* 'number' => 45,
* 'format' => 'flat',
* 'separator' => "\n",
* 'orderby' => 'name',
* 'order' => 'ASC',
* 'exclude' => null,
* 'include' => null,
* 'topic_count_text_callback' => default_topic_count_text,
* 'link' => 'view',
* 'taxonomy' => 'post_tag',
* 'echo' => true,
*/
See the wp_tag_cloud codex page for more details on the other things you can change, for example, have a cloud of custom taxonomies or change the font sizes of the smallest and largest tags.
You would put your code in your theme’s functions.php
Sebastian
Hi, this is exactly what I was looking for, only with taxonomy set to “Categories” instead of “Tags”. Any idea how to set-up the filter to exclude specific categories from the “tag”/category cloud?
Jo Waltham
Untested, but I think you just need to supply the ID of the category you wish to exclude to the above code. Try it and let me know if it works.
Sebastian
Thank you so much!!! It works like a charm!! π
Michael
Users who don’t feel comfortable writing their own code could also install the Tag Groups plugin http://wordpress.org/extend/plugins/tag-groups/ and leave all tags they don’t want to display unassigned. π
John
Won’t this just get overwritten each time you update wordpress though?
Jo Waltham
Hi John. Aha! I didn’t make that clear in the post and I’ve edited it to say that you use the filter to add your function and you put both in your functions.php (unless you want to create your own plugin for it).