Hello Matt!
I have tried the code you provided, and it works as expected. Please make sure you already have tags in your website.
Don’t forget to copy the [wpb_popular_tags] shortcode in the place when you want to show the cloud of tags. You can past it on any page in your website or in a text widget from your dashboard in Appearance >> Widgets.
Please try this and let me know if all is fine and working now. 🙂
Hmmm very strange! Well thanks for letting me know it’s working on your end. It must be something to do with my theme maybe? I have two custom taxonomies and I know I’m using the right ones. Is there any way to debug it to see where the problem might be?
Actually you know what, I don’t think the function wp_generate_tag_cloud allows for a custom taxonomy. So how would I edit the code to only pull tags from a specific taxonomy?
Nevermind, I think I figured out a solution but using this code instead:
function my_cloud() {
if (function_exists('wp_tag_cloud'))
return wp_tag_cloud(array(
'smallest' => 9,
'largest' => 20,
'unit' => 'pt',
'number' => 10,
'format' => 'list',
'separator' => "\n",
'orderby' => 'name',
'order' => 'ASC',
'link' => 'view',
'taxonomy' => '',
'show_count' => 0,
));
}
add_shortcode('popular_tags', 'my_cloud');
-
This reply was modified 7 years, 11 months ago by
Matt Rittman.
-
This reply was modified 7 years, 11 months ago by
Matt Rittman.
Nice! One thing though, wp_tag_cloud() echoes by default. Add 'echo'=> false, to your arguments array.
I’m assuming you will also add a taxonomy value for your custom taxonomy.
I don’t really understand the whole echo thing lol. I went ahead and added it to my arguments array, but it didn’t seem to change anything. What does it do that I’m not seeing? Yeah, I have a taxonomy, but I just removed it for the sake of this thread 😀
Thanks @bcworks!
When we echo from a shortcode handler, we cannot predict where the output will occur. It’s often not where the shortcode was placed. In your case it sounds like it didn’t make any difference, a fortunate happenstance. In any case, it’s a firm rule that shortcode handlers must return the desired output and not echo out. Something to keep in mind for your next shortcode 🙂