Custom tag pages for WordPress

Technology Blog

What’s a “custom tag page”? Generally when you click on a tag link in a cloud such as that in the sidebar of this site or at the bottom of an article, you’ll be taken to a page that lists all the articles having that tag. From an SEO perspective this is less than ideal, because in web searches the tag page will have to compete with other pages which have a lot more relevant content. In this article I show how to create custom tag pages that have much more search engine appeal.

For example you have a tag such as “fish” the tag page may be great for navigation purposes in that it will help visitors find all your fish-related articles, but it won’t tend to attract the search engines because it will have little in the way of specific content. To make a better page, you need to add some paragraphs of text that directly relate to that topic.

One solution to this problem is to create a custom page, with content tailored for the search engines. This article gives one way of solving the problem, which I am not awfully keen on as it goes against the concept of a CMS in that it requires you to put content directly into theme templates.

Happily there is a better way, because in WordPress since version 2.8 there is the ability to add a description field for each tag. On the Dashboard under Posts there is a link headed “Post Tags”. From there, click on any tag and you’ll be taken to a page where you can edit its name, “slug” (the short name used in permalinks) and description. Normally the description is not visible anywhere, but it is accessible to template code so it can be used to hold the additional content referred to earlier.

Pick a tag or two that you think will match popular searches, and add descriptions to them. You can include some HTML, and your description will be automatically paragraphed wherever you include two successive linefeeds, just like when you write an article in HTML mode.

To make the description appear, you need first to create a tag page template, if your theme does not have one. You’ll want to take a copy of either index.php or archive.php and name the new file as tag.php. Then, before the loop code which displays the list of posts you’ll want to insert something along these lines:

<?php $tag_desc = tag_description(); ?>
<?php if($tag_desc) : ?>
<div class="tag-description">
<?php print $tag_desc ;?>
</div>
<?php endif; ?>

If you are using a theme framework such as Carrington, you’ll need to edit and/or create different template files. The tag_description() call may need to be modified as well to supply the id of the tag explicitly, like this:

$tag_desc = tag_description(get_query_var('tag_id'));

The tag page template can also be modified as you see fit to list the related posts in the best form for your needs (eg. just the titles, with an excerpt rather than a teaser and so on.). An example of a page created using this technique can be seen on our Drupal Module Development tag page.

3 Responses to “Custom tag pages for WordPress”

  1. Movie Reviews

    Thanks, this was informative! But I need something more, like apart from adding descriptions to each tag that will be displayed on its corresponding tag page, I would like to add some image also relative to that tag.
    Like in our case, I am tagging each movie with their star cast and their tag pages will be having movies for that actor. But Apart from some description, I would also like to add an image or may be an image gallery for that actor. So, could you tell how can this be accomplished?
    For your reference, here is my site which is basically an entertainment site for Movie Reviews.

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>