WordPress wp_tag_cloud() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Template tag

Definition

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.

Syntax

Pass an array of arguments. Every argument is optional.

WordPress
wp_tag_cloud();
wp_tag_cloud( array(
  'number'  => 10,
  'orderby' => 'count',
  'order'   => 'DESC',
) );
CallWhat 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.

Full declaration
WordPress
wp_tag_cloud( array|string $args = '' ): void|string|string[]

Parameters

ParameterDescription
smallestOptional. Font size of the least used tag. Default is 8.
largestOptional. Font size of the most used tag. Default is 22.
unitOptional. CSS unit for the size, such as pt or px. Default is pt.
numberOptional. Maximum number of tags. Default is 45.
formatOptional. flat, list, or array. Default is flat.
orderbyOptional. name or count. Default is name.
taxonomyOptional. The taxonomy to use. Default is post_tag.
echoOptional. true prints the cloud. false returns it. Default is true.

Return Value

Return ValueDescription
voidNothing is returned when echo is true.
stringThe 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.

WordPress Examples

Three short theme examples. Each one has a sample output.

Example 1 — Basic cloud

Print the default tag cloud.

WordPress
<?php wp_tag_cloud(); ?>

How It Works

  1. WordPress loads your tags.
  2. The most used tag gets the biggest font.
  3. The links are printed one after another.

Example 2 — Custom sizes

Show the top tags with your own font sizes.

WordPress
<?php
wp_tag_cloud( array(
  'number'   => 10,
  'smallest' => 12,
  'largest'  => 24,
  'unit'     => 'px',
  'orderby'  => 'count',
  'order'    => 'DESC',
) );
?>

How It Works

  1. number limits the cloud to 10 tags.
  2. smallest, largest, and unit set the font sizes.
  3. orderby and order show the busiest tags first.

Example 3 — Return the cloud

Save the cloud in a variable and wrap it in a box.

WordPress
<?php
$cloud = wp_tag_cloud( array(
  'number' => 20,
  'echo'   => false,
) );
if ( $cloud ) {
  echo '<div class="tag-cloud">' . $cloud . '</div>';
}
?>

How It Works

  1. 'echo' => false returns the cloud as a string.
  2. if ( $cloud ) skips the box when there are no tags.
  3. You add your own div and class.

Frequently Asked Questions

It prints a tag cloud. Tags used more often are shown with a bigger font size.
wp_tag_cloud() fetches the tags and prints the cloud. wp_generate_tag_cloud() only builds the HTML from tags you already have.
Up to 45 by default. Change it with the number argument. Use 0 for all tags.
Yes. Use 'taxonomy' => 'category'. Categories that have posts will appear.
Set 'echo' => false. With the default flat format, you get an HTML string.

Back to the Function Index

See all sixteen category and tag function guides in one place.

Category Functions Index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful