Skip to content

Using Tags Effectively in WordPress

Tags are a great way of associating the same type of content together, and they’re something that many bloggers use regularly, but using them effectively? That’s what this post will tell you how to do.

Using the same tags

Tags only really work if you use the same tags over and over again. For example, if you wrote a post about cheese, you might tag it ‘Cheese’. Write a second post about cheese, tag it ‘Cheeses’ and the tags become useless. Bascially, you must tag similar posts with the same tag.

Putting this in real terms: on my other site, Nometet.com, each post gets tagged with the game it is related to:

And as you can see, you’re left with a rather nice tag cloud. Had some games been tagged ‘Assassin’s Creed’ whilst others ‘Assassins Creed’, you wouldn’t get the same look. Heck, it’d look like the one here on [wp]!

Implementing the tags

Within the loop

With tags made, you’ve now got a number of options for implementing the tags. Used within the loop, you can display tags with the template tag

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

Obviously, this is going to output the current post’s tags, with options for text before, between and after. Say you wanted to have ‘Tagged: tag 1, tag 2, tag 3.’ You’d need the code:

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

With all the commas that looks slightly unclear, but look at it this way and it’s a bit clearer: each section is in quotation marks ‘ ‘ , with a comma ‘,’ between the sections.

Outside the loop

Outside of the loop, you can display a rather lovely tag cloud. The good news is that it’s really easy to do. The easiest way is through widgets: if your theme is widgetised, under Widgets you can drag and drop the tag cloud widget, give it a title and save it. You’ll then have a nice tag cloud. Simple.

Of course, this wouldn’t be a [d] blog if we just left it with widgets! Lets achieve the same thing with the template tag:

<?php wp_tag_cloud(); ?>

Of course, by using a template tag, you’ve got the added advantage of being able to customise – as the codex shows, the tag has a ton of options:

smallest – The smallest tag (lowest count) is shown at size 8
largest – The largest tag (highest count) is shown at size 22
unit – Describes ‘pt’ (point) as the font-size unit for the smallest and largest values
number – Displays at most 45 tags
format – Displays the tags in flat (separated by whitespace) style
orderby – Order the tags by name
order – Sort the tags in ASCENDING fashion
exclude – Exclude no tags
include – Include all tags
link – view
taxonomy – Use post tags for basis of cloud
echo – echo the results

The ones that we’re interested in are ‘smallest’ and ‘largest’ – they let you choose the minimum and maximum number of entries a tag must have in order to be displayed. Say I wanted a minimum of 2 and a maximum of 10, I’d need the following:

<?php wp_tag_cloud('smallest=2&largest=10'); ?>

Concluding

And with that, we’re done. Hopefully you’ve not got a solid understanding of how tags work and how you can implement them effectively into your WordPress [theme].

Yay! 🎉 You made it to the end of the article!
Alex Denning
Share:

3 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Aayush
October 6, 2010 9:16 pm

Out of loop use of tags without widgets was just what I needed…worked great for me, thanks.

Bill Ludwig
September 19, 2009 4:29 am

Nice post, especially the part about keeping the same tags. I always try to use the singular form and present tense. That rule of thumb helps when I’m using a CMS that doesn’t implement tags as well as WordPress.

Using Tags Effectively in WordPress | ShareFavorite
September 18, 2009 5:26 pm

[…] posted here: Using Tags Effectively in WordPress Related […]

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!