Implementing Tags into your WordPress blog

By jblanton | WordPress Coding & Design

Jan 17

A tag is a keyword used to describe a picture, video, blog entry, or anything else to help with classification and search information.

In the release of WordPress 2.3 tagging was officially introduced into the core WordPress application. Prior to this implementation many of us used plug-ins like Ultimate Tag Warrior, Jerome’s Keywords, Simple Tags and Bunny’s Technorati Tags. Since the release of WordPress 2.3 many if not all of these plug-ins have now been upgraded and work with WordPress 2.3 and later. So if you’re using them and like them you can still use them.

Now for those of you that have not used Tags in the past and would like to take advantage of WordPress’ new feature let’s get started. The first thing you will notice is in the write a new post section within WordPress called tags. It’s the 1 line form field under the post box. Just type your tags separated with a comma after each. OK now we have the easy part done. Don’t worry the next part isn’t much harder.

Now that you have your post tagged you want the tags to show up on your blog. Chances are your blog template wasn’t built with the php to display the tags. The good news this is really easy to correct. To start lets go to the theme editor in WordPress and look for The Loop. Keeping it very basic, insert this code: <?php the_tags(); ?> before or after <?php the_content(); ?>. That should display the tags on your page either just before or just after the post body. Once you see it in action you can play around with moving it around to get the tags to show up exactly where you want them.

Below is that basic usage code to help explain it a little better.

<?php the_tags(‘before’, ’separator’, ‘after’); ?>

Let’s take a look at some other examples you can use:

<?php the_tags('Tagged with: ',' • ','<br />'); ?>

Tagged with: WordPress • Computers • Blogging

<?php the_tags('<ul><li>','</li><li>','</li></ul>');?>

• WordPress
• Computers
• Blogging

<?php the_tags('Tagged in: ',' | '); ?>

Tagged in: WordPress | Computers | Blogging

WordPress 2.3 also added the ability to add your tags as a tag cloud.

Use this <?php wp_tag_cloud(’smallest=8&largest=36&′);   ?> The number of words displayed this way will be a max of 45 but you can change that by using this code. <?php wp_tag_cloud(’smallest=8&largest=36&number=150′);   ?> By changing the number= the tag cloud will display that number of tags if you have that many.

About the Author

Spale January 17, 2008

Great post, that was just i needed.

Can tags be shown on special page, for example as normal Archive page on WordPress blog?

jblanton January 17, 2008

Thanks Spale.

Yea you should be able to add the code to any pages in your WP Theme. Might take some trial and error to get it to show up the way you want.

Not John Chow January 17, 2008

Is "The Loop" part of a specific file ❓ I am still unfamiliar with php, but would like to learn more.

Cigar Jack January 17, 2008

Now if only I had some magical tagging tool to add tags to my 400 old posts that don't have any.

Guillermo January 17, 2008

Great, great post! I've been wainting for such a good explanation of WP tags for a long time!


jblanton January 17, 2008

@not John Chow – The loop is the part of the WordPress code that displays your posts. Its usually included in the index.php and single.php pages of your theme at a minimum. Take a look at the Link in this post title The Loop that takes you to the WordPress documentation. Hope that helps.

@Cigar Jack I feel your pain. Pull a nice Maduro out, that should help ease the pain. 😉

@Guillermo Thanks. Hope this helped.

Martin Welch January 17, 2008

Thanks for explaining more on how to implement tags in WordPress. I

got more ideas on how to use it. :)

Fred Peters January 18, 2008

What is the advantage of tags? Is it just so that people can find your older posts? Does tagging help with SEO?

Barry O January 18, 2008

I found Simple Tags to be a great plug-in for managing tags. It has some really cool features plus, it provides a more configurable tag cloud than the standard WordPress one.

Comments are closed