Title: Tag Cloud Shortcode
Last modified: May 27, 2018

---

# Tag Cloud Shortcode

 *  [Matt Rittman](https://wordpress.org/support/users/mrittman/)
 * (@mrittman)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/tag-cloud-shortcode-3/)
 * Hey guys, I tried creating a custom tag cloud shortcode, but it’s not showing
   the tags on the front of my site. Here’s the code I’m dropping into my functions.
   php file:
 *     ```
       function wpb_tag_cloud() { 
       $tags = get_tags();
       $args = array(
           'smallest'                  => 10, 
           'largest'                   => 22,
           'unit'                      => 'px', 
           'number'                    => 10,  
           'format'                    => 'flat',
           'separator'                 => " ",
           'orderby'                   => 'count', 
           'order'                     => 'DESC',
           'show_count'                => 1,
           'echo'                      => false
       ); 
   
       $tag_string = wp_generate_tag_cloud( $tags, $args );
   
       return $tag_string; 
   
       } 
       // Add a shortcode so that we can use it in widgets, posts, and pages
       add_shortcode('wpb_popular_tags', 'wpb_tag_cloud'); 
   
       // Enable shortcode execution in text widget
       add_filter ('widget_text', 'do_shortcode');
       ```
   
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Ftag-cloud-shortcode-3%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [Anass Rahou](https://wordpress.org/support/users/ranss/)
 * (@ranss)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/tag-cloud-shortcode-3/#post-10330469)
 * 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. 🙂
 *  Thread Starter [Matt Rittman](https://wordpress.org/support/users/mrittman/)
 * (@mrittman)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/tag-cloud-shortcode-3/#post-10331698)
 * 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?
 *  Thread Starter [Matt Rittman](https://wordpress.org/support/users/mrittman/)
 * (@mrittman)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/tag-cloud-shortcode-3/#post-10332045)
 * 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?
 *  Thread Starter [Matt Rittman](https://wordpress.org/support/users/mrittman/)
 * (@mrittman)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/tag-cloud-shortcode-3/#post-10332589)
 * 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](https://wordpress.org/support/users/mrittman/).
    -  This reply was modified 7 years, 11 months ago by [Matt Rittman](https://wordpress.org/support/users/mrittman/).
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/tag-cloud-shortcode-3/#post-10332890)
 * 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.
 *  Thread Starter [Matt Rittman](https://wordpress.org/support/users/mrittman/)
 * (@mrittman)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/tag-cloud-shortcode-3/#post-10333090)
 * 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](https://wordpress.org/support/users/bcworks/)!
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/tag-cloud-shortcode-3/#post-10336859)
 * 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 🙂

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Tag Cloud Shortcode’ is closed to new replies.

## Tags

 * [custom](https://wordpress.org/support/topic-tag/custom/)
 * [tags](https://wordpress.org/support/topic-tag/tags/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 7 replies
 * 3 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [7 years, 11 months ago](https://wordpress.org/support/topic/tag-cloud-shortcode-3/#post-10336859)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
