Example 1 — Basic cloud
Print the default tag cloud.
<?php wp_tag_cloud(); ?> How It Works
- WordPress loads your tags.
- The most used tag gets the biggest font.
- The links are printed one after another.

In WordPress, wp_tag_cloud() prints a tag cloud. Popular tags are shown in a bigger font and rare tags in a smaller font.
It fetches the tags for you and calls wp_generate_tag_cloud(). It prints the cloud by default. Set echo to false to return it.
Pass an array of arguments. Every argument is optional.
wp_tag_cloud();
wp_tag_cloud( array(
'number' => 10,
'orderby' => 'count',
'order' => 'DESC',
) ); | Call | What it does |
|---|---|
wp_tag_cloud() | Prints a cloud of up to 45 tags. |
wp_tag_cloud( array( 'number' => 10 ) ) | Prints only 10 tags. |
$cloud = wp_tag_cloud( array( 'echo' => false ) ) | Returns the cloud instead of printing it. |
Tags are used by default. Use the taxonomy argument for another taxonomy.
wp_tag_cloud( array|string $args = '' ): void|string|string[] | Parameter | Description |
|---|---|
smallest | Optional. Font size of the least used tag. Default is 8. |
largest | Optional. Font size of the most used tag. Default is 22. |
unit | Optional. CSS unit for the size, such as pt or px. Default is pt. |
number | Optional. Maximum number of tags. Default is 45. |
format | Optional. flat, list, or array. Default is flat. |
orderby | Optional. name or count. Default is name. |
taxonomy | Optional. The taxonomy to use. Default is post_tag. |
echo | Optional. true prints the cloud. false returns it. Default is true. |
| Return Value | Description |
|---|---|
| void | Nothing is returned when echo is true. |
| string | The cloud HTML, when echo is false and format is flat or list. |
| string[] | An array of links, when echo is false and format is array. |
Three short theme examples. Each one has a sample output.
Print the default tag cloud.
<?php wp_tag_cloud(); ?> Show the top tags with your own font sizes.
<?php
wp_tag_cloud( array(
'number' => 10,
'smallest' => 12,
'largest' => 24,
'unit' => 'px',
'orderby' => 'count',
'order' => 'DESC',
) );
?> number limits the cloud to 10 tags.smallest, largest, and unit set the font sizes.orderby and order show the busiest tags first.Save the cloud in a variable and wrap it in a box.
<?php
$cloud = wp_tag_cloud( array(
'number' => 20,
'echo' => false,
) );
if ( $cloud ) {
echo '<div class="tag-cloud">' . $cloud . '</div>';
}
?> 'echo' => false returns the cloud as a string.if ( $cloud ) skips the box when there are no tags.div and class.See all sixteen category and tag function guides in one place.
9 people found this page helpful