Feeds

How To Display Most Popular Tags In WordPress Using the WP_TAG_CLOUD Function

Submitted by Ryan Caldwell on April 13, 2008 - 12:17pm in

I'm sure there are many people out there like me who started off displaying the default number of tags on their WordPress 2.3+ blogs. After a month or so of posting, you maybe have starting realizing that tags are like cats; uncontrolled, they can just keep multiplying over time and crowding out the spaces where they live;-)

The default setting for the wp_tag_cloud function is 45 tags. But for many WordPress themes, this number is too large for the space allocated to your tag cloud. The good news is that there is an easy way to trim down the total number of tags that get shown.

Here's the code to display the 30 most popular tags on your blog, with the smallest font size at 8 and the largest font size at 22:

<?php wp_tag_cloud('smallest=8&largest=22&number=30'); ?>

If you want to show more or less tags, just change the number 30 to whatever you want. If you want the most popular tags to look bigger, just increase the number 22 to whatever you want. If you want the least popular tags to look smaller, just change the 8 (but don't go too small or else no one will be able to read).

So all you need to do to contain tag sprawl, is to spay or neuter your wp_tag_cloud function with the "number" variable.


Where to Find the <?php

Where to Find the

<?php
wp_tag_cloud
();
?>
?

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <h2> <h3> <h4> <img> <div> <a> <em> <strong> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <span> <table> <td> <tr> <caption> <th> <hr> <pre> <br> <p> <object> <param> <embed>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
1 + 4 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.