WordPress 2.3 quietly introduced a powerful new feature that had previously only been available using plugins: tagging.

There are several ways to list your tags:

  • Before or after each post, so people can click a tag to see other posts you’ve tagged the same way
  • In a tag cloud in your sidebar
  • On a tag archive page

I’ve found that tag archive pages are indexed very well by search engines, so I highly recommend using tags. But how should you use them, and how should they relate to WordPress categories?

As Lorelle said several years ago, tags are like a blog’s index, and categories are like the table of contents. Tags are great for SEO, but you don’t want to list a zillion of them in your sidebar; you want a concise list of categories.

It’s fine to have a zillion tags, but they’re better listed in a tag cloud or on an archive page. With that in mind, let’s look at how tags can become a part of your blog.

Listing the Tags for Each Post

Most WordPress themes have a post metadata section either before or after the body of the post, which includes the date, author, and comment link. This is a great place to display the tags for that post.

In this section, you can add
<?php the_tags('Tags: ', ', ', ' | '); ?>
to display a comma-separated list of the post’s tags, followed by a | mark. The parameters for this function are, respectively, what goes before the tags, what separates the tags, and what goes after the tags. Full documentation for this template tag (WP Codex)

Since tags are likely to make the post metadata section take up more than one line, make sure your theme still looks good if this section is several lines long; for example, some themes don’t leave enough linespacing because the theme author assumes it’ll only be one line long.

Since this tag applies to a specific post, it must be in the loop, not in the sidebar, header, or footer.

Listing Tags in a Sidebar Cloud

A tag cloud is a great way to visualize the topics you blog about, because the size of each tag is proportional to the number of times you’ve used it. This may not be immediately obvious on a new blog, but if you have 1,000 posts, and 800 of them are about horses and only 100 are about fish, the “horse” tag will be much bigger than the “fish” tag (assuming you’ve tagged your posts).

Here’s the function to display the tag cloud:
<?php wp_tag_cloud(''); ?>

You can put this tag in the sidebar or footer of your site, but don’t put it in the loop.

You can customize the minimum and maximum size of the items in the tag cloud, as well as how many to display and how to sort them. Full documentation for this template tag (WP Codex)

Displaying Tags on a Tag Archive Page

If you have tons of tags and you want to display them all in one place, but not on the main page of your blog, you can create a tag archive page. Here’s how.

  1. Make a copy of your single.php or index.php template, and name it something like “tag-archive.php”
  2. At the top of your tag archive template, insert this:<?php
    /*
    Template Name: Tag Archive
    */
    ?>
  3. Replace everything from
    <?php if (have_posts()) : ?>
    to
    <?php endif; ?>
    (aka The Loop) with the <?php wp_tag_cloud(); ?> function. You can download a Kubrick-compatible tag archive template here.
  4. Upload the new template file tag-archive.php to your theme folder.
  5. Create a new page and call it something like “Tag Archives”. Under Page Template in the sidebar, select the new template you created. Leave the body of the page blank, and publish it.
  6. Make sure you link to the new page in your navbar or sidebar so people can find the tag archive page

Converting Categories to Tags

WordPress 2.3+ also has a category-to-tag converter, which you can use for categories that don’t have very many posts in them. To use it, go to Manage -> Import, and select Categories to Tags Converter.

The converter lists all of your categories and the number of posts in each. Select the categories you want to convert using the checkboxes, and hit Convert. This will add the tags and delete the categories you select, so be selective and don’t eliminate all of your categories.

Importing Plugin Tags to WordPress Tags

If you’ve been using a tagging plugin like Ultimate Tag Warrior or Bunny’s Technorati Tags, you can convert your tags to WordPress native tags (since they’re stored in a different place in the database). The converters (including the aforementioned category-to-tag converter) are listed in the WordPress admin panel under Manage -> Import.