Archives by Month

Support this Site!

You may have noticed that there's very little third-party advertising on this site. I'd like to keep it that way. Here's how you can help:

  • Buy my books. They're available at great prices on Amazon.com.
  • Check out my training videos on Lynda.com. It's a great source for "all you can eat" training.
  • Donate a few dollars. It'll help cover my hosting costs and give you a chance to tell me what you want to see covered here.
  • Comment on blog posts. You can help get a discussion going that can benefit others, making the site more valuable for everyone.

How To Customize WordPress’s Tag Cloud Widget

You don’t have to use it with default settings.

If you use WordPress widgets on your self-hosted WordPress blog, you may not be fully satisfied with the way the Tag Cloud widget looks and works on your site. I know I wasn’t. The maximum font size was too large for the most commonly used tag (helicopters, on my blog) to fit into the column in which I’d put it. Since I wanted my tag cloud in the narrow column in which it resided, I had to make a change.

The answer is to modify the wp_tag_cloud function in the category-template.php file. It’s remarkably easy to do. Here’s how.

  1. Open the file /wp-includes/category-template.php.
  2. Scroll down to the line that begins function wp_tag_cloud. If you’re using WordPress 2.7 and haven’t made any other changes to this file, you should find it at line 552. (You can always do a search for it; I found the general area by searching for “tag cloud.”)
  3. Make changes in the array as follows:

    Tag Cloud Function

    • To specify the smallest font size, set the value after ‘smallest’. The default is 8 points.
    • To specify the largest font size, set the value after ‘largest’. The default size is 22 points.
    • To specify the maximum number of tags included in the cloud, set the value after ‘number’. The default number of tags is 45.

    My Tag CloudI changed my settings to 6, 16, and 75 respectively. You can see the results in the screenshot here, as well as in the sidebar for my blog, An Eclectic Mind.

  4. Overwrite the existing file with the changed file.

When you reload a page that uses the Tag Cloud widget, your changes should appear immediately.

Keep in mind that if WordPress is updated and the file you changed is replaced, you may have to repeat these steps to reset your defaults.

Learn More

Lynda.comLearn more about working with a self-hosted WordPress 2.7 installation — or WordPress.com. Check out my WordPress courses on Lynda.com.

14 comments to How To Customize WordPress’s Tag Cloud Widget

  • thanks! i have a little troubel with mine so found some usefull hints here in this post!

  • Maria,

    This is a good reference but it would be much better to set the arguments within the cloud tag function. Your example modified the core WP files: One would have to remember to modify this file when a change/updgrade happens with WP.

    Typically the cloud tag is going to be located in the sidebar.php file within the theme directory.

    A couple of examples of the arguments:

    
    
      <?php wp_tag_cloud('smallest=8&largest=36'); ?>
    
      <?php wp_tag_cloud('smallest=8&largest=36&order=RAND&number=75'); ?>
    
    

    Details on the cloud are described in the codex:

    Template Tags/wp tag cloud

    Rick

    P.S. Have you been working with Child template themes within WordPress. Child themes are a great aspect in that you can leave the files of the parent theme alone and inherit their style and function within the child theme. One can do all of their changes, edits and adjustments on the child theme files to customize the theme. Much easier to track changes.

  • Rick: This is a good point, and I agree that if you’re modifying the sidebar template file to insert the tag cloud widget, your way IS the way to go. However, I’m providing instructions for modifying the default Tag Cloud widget for folks who want to use widgets rather than hard-code content in their sidebar theme.

    Agreed also about the biggest drawback of my method: that you must remember to modify the category-template.php file each time you upgrade WordPress. I think there IS a way around this, but I haven’t had time to research it.

  • I did spend a few minutes trying to find a hook to the default tag cloud widget but couldn’t find anything simpler than creating another widget. Much more complicated than your change.

    Configurable Tag Cloud (CTC) is a plug-in which provides a Widget for the Tag Cloud. CTC provides a panel to configure the tag cloud parameters. (My test showed it worked with WP 2.7).

    Here is an interesting tag cloud plug-in:

    WP Cumulus Flash Based Tag Cloud

  • RickHap: Thanks for the CTC info and link. I’d much rather use something like that than have to manually hack code each time I want to make a change or I update WordPress.

  • Worked flawlessly on my site, just as advertised. Thanks!

  • Take a lesson from Drupal and never hack core or end up having to re-do everything you customized every time you upgrade.

    Figure out a way to do it via the functions script or find a plug-in. Otherwise you are creating more work for yourself or eliminating a seamless upgrade path.

    Good info nonetheless, but you have to be careful with the changes you make.

    Dave´s last blog post: Cinco de Mayo

  • Dave: You’re right, of course. The problem with hacking — even a simple hack like this — is that when you update the software, the hack is overwritten with the new files.

    I’ve since found a plugin that does what I need: Simple Tags. Not only does it offer a customizable Tag Cloud widget, but it adds a bunch of tag management features.

    Thanks for the reality check!

  • Kim

    You guys rock. Your discussion has saved me many hours of work. So simple when we all share what we love!!

  • BJ

    Thanks so much, I knew this snippet of code had to be in there somewhere.. I saw so many other worse ways of doing it before finding this.

  • Thanks Maria! I was Googling how to do exactly this, and your advice was spot on. I now have an expanded tag cloud, but using smaller fonts throughout. Perfect!

  • Tom

    Thanks!
    Another few lines (601) down is where you can change the link hint to say “posts” instead of “topics”. I’ve never understood why the default is “topics” when it’s linking to posts.

    function default_topic_count_text( $count ) {
    return sprintf( _n(‘%s post’, ‘%s posts’, $count), number_format_i18n( $count ) );
    }

    cheers!

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>