How to Display Custom Taxonomies on WordPress Tag Cloud Widget

cloud WordPress has few default widgets and one of them is tag cloud widget. By default, this widget allows you to creatively display your 20 top tags. This widget is highly customizeable and these are all parameters can be accepted by the widget.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<?php
// Parameters accepted by tag cloud widget
// @url http://codex.wordpress.org/Function_Reference/wp_tag_cloud
$args = array(
'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,
'child_of' => null
); ?>
view raw tags-widget.php hosted with ❤ by GitHub

As you can see on line 19, we can specify the taxonomy to be displayed on the cloud widget. To display custom taxonomies on this widget, simply replace post_tag with your custom taxonomies name. Here’s a working code that can be placed on your child theme’s functions.php file:

1 2 3 4 5 6 7 8 9 10
<?php
//* Display custom taxonomies on WordPress tag cloud widget
add_filter('widget_tag_cloud_args','afn_display_custom_tax');
function afn_display_custom_tax($args) {
$args = array(
'taxonomy' => 'mycustom_tax',
return $args;
}
view raw functions.php hosted with ❤ by GitHub

Don’t forget to replace mycustom_tax with your custom taxonomies name. That’s all you need to do, it couldn’t be much simpler than that. We hope this tutorial helped you to display custom taxonomies on the tag cloud widget. Don’t forget to check out our article on customizing WordPress tag cloud widget for more examples on customizing the widget. For more info about WordPress tag cloud widget, be sure to check out WordPress Codex.

Leave a Reply

Your email address will not be published. Required fields are marked *