Displaying WordPress 2.3 Tags in your Theme

With the release of WordPress 2.3, the developers incorporated tagging into WordPress. This had a couple of knock-on effects for me. First of all, UTW no longer worked, and secondly there is no way to display WordPress tags unless your theme supports it.

I tried the WordPress Plugin page, but couldn’t find what I wanted there. So I decided that I would manually edit my theme to add tags to the end of each post. As it turned out, it was easier than I thought.

The first step was to download local copies of the files I needed to modify. These files are located in your blog directory:


blog_dir/wp-content/themes/theme_name/index.php
blog_dir/wp-content/themes/theme_name/single.php

Within each of these files you’ll see a line such as this:


<?php the_content('Read the rest of this entry'); ?>

If you want your tags to appear after the post, then add this line immediately after it:


<?php the_tags('<p>Tags: ', ', ', '</p>'); ?>

You may need to surround your tag line with DIV tags so as to seperate it from the rest of the post. If this is the case, then the lines you insert will look something like this:


<div class="post-tags">
<?php the_tags('<p>Tags: ', ', ', '</p>'); ?>
</div>

If you want to apply styles to your tags, then you will also need to edit the stylesheet provided with your theme. The stylesheet is usually named “style.css”.

Repeat the above steps for both index.php and single.php. When you’re finished, upload the modified files to your blog server and overwrite the old ones. Refresh your browser page to see the changes.

Tags: , , ,

Comments are closed.