# Tag Cloud Shortcode

> Adds a [tag_cloud] shortcode to show a tag cloud inside a page or post, with control over how many tags appear and how large they get.

- Type: PHP
- Runs: Run everywhere
- Category: [Archives](https://wpide.com/library/category/archive/)
- Tags: shortcode, tags, tag-cloud
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/tag-cloud-shortcode/

## Code

```php
add_shortcode( 'tag_cloud', function ( $atts ) {
    $atts = shortcode_atts( array(
        'number'   => 45,
        'smallest' => 0.8,
        'largest'  => 1.6,
        'taxonomy' => 'post_tag',
        'orderby'  => 'name',
    ), $atts, 'tag_cloud' );

    $cloud = wp_tag_cloud( array(
        'number'   => absint( $atts['number'] ),
        'smallest' => (float) $atts['smallest'],
        'largest'  => (float) $atts['largest'],
        'unit'     => 'em',
        'taxonomy' => taxonomy_exists( $atts['taxonomy'] ) ? $atts['taxonomy'] : 'post_tag',
        'orderby'  => 'count' === $atts['orderby'] ? 'count' : 'name',
        'order'    => 'count' === $atts['orderby'] ? 'DESC' : 'ASC',
        'echo'     => false,
    ) );

    return $cloud ? '<div class="wpide-tag-cloud">' . $cloud . '</div>' : '';
} );
```

## Notes

Example: [tag_cloud number="30" smallest="0.8" largest="1.6" taxonomy="post_tag"]. Sizes are in em.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Tag Cloud Shortcode" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
