Today we’ll learn How to add Tag Support by hacking your WordPress theme!
This is day #15 of 30 WordPress Hacks in 30 Days.
If you’re using WordPress 2.3x or 2.5 or higher you have the ability to use “tags”. If you use social media at all, you should already know what a tag is. Basically it’s just a piece of metadata, a “descriptor” of some kind. When you blog, it’s also another way to pigeonhole and file your content. The implementation of tags in WordPress is very important, because it keep people from “using categories as tags” as many of us have done over the years. There were dozens of plugins available to add tags to your WordPress blog, but now all that functionality is available without using any plugins at all.
Think of categories as high level descriptions. What do you like to blog about? Movies, Music, Politics, and Web Design. Those are categories. However, when you blog – the tags would be Obama, John Candy, AC/DC, and HTML. Get it? All you have to do is enter description tags when you blog, along with a category. Now you’re probably wondering, what do I do with that information?
Depending on how old your theme is it may or may not have “tag support”, which means that it might not be coded to do anything at all with those tags you’re entering. The first thing you can do is to add a (now famous) “tag cloud” in your side bar like I did, with this code:
Popular Tags
If you want to know more about how that codes works and how you can modify it, visit the WordPress Codex Tag Cloud Page.
Another thing you can do is to add the tags you used beneath your post by adding some code to your single.php file (for single posts). You could do it on your index.php home page as well, but I don’t much see the point in that. All you have to do is add the following code near the end of the loop to display the tags used at the end of the post:
Tags: ', ', ', ''); ?>
So, now we’ve talked about how to modify your theme to add the tags used after a post, and how to place a tag cloud in your sidebar (without using a plugin). Click on one of the links in my post (to a tag) or my tag cloud and you’ll see (much like a category page) it goes to a “tag” page, or something like site.com/tag/wordpress-hack.
Be default WordPress will look for the “tag.php” file (that most themes don’t have), and if there isn’t one your archive.php will be used by default. You could just leave this as-is, or create your own custom “tag.php” to make your tag pages unique. One way to do this would be to add a “tag cloud” to the top of each tag page. The WordPress Codex Tag Page has more information on creating a custom tag.php file for your theme.
This post was all about “how to add tag support to your WordPress theme”. In a future post, I’ll show you what you need to know about tagged pages and WordPress SEO. As always, if you have something to add to make this post better, or a question – comment now!






You have a really good tutorial there quick and easy to follow, you should amke it into an article and do some article submissions with it to attract more people to your site.
Really like that and keep up the good work 🙂
unique articless last blog post..The Art Of Online Writing
LOL I was just looking for this yesterday! Thanks for the little tidbit!
Erikas last blog post..1
Categories are nice to start your site off. Use the descriptions of the categories to add keyword content like JT talks about and then the tags to get specific. I don’t add tags till I have some pages going. . . looks bad to have one post in ten places.
I haven’t found a problem with duplicate content using tags. I know it’s a big topic but google seems to be ok with tags. I’ve been adding tons on my wordpress.com blog and haven’t seen any problems. However, I do like to keep them to a smaller number on my main blogs but I’ve seen others that use them by the truck loads.
CJs last blog post..Sorbs
Update:
Just spent the past few days studying up on tags, technorati, and other blog search engines.
First, we all should be using the rel-“tag” (note that – should be an = sign) on all our links that have key words. Many of those links you may not want to have a tag for your visitors to follow. This works well with blog search engines, also. This allows your keywords to be tagged without needing to put a tag at the bottom of your post
Remember that technorati uses + while wordpress uses – between words. Technorati also uses the – for tags but they aren’t the primary tags, thus a multi word tag on technorati should be worda+wordb+wordc while that will be worda-wordb-wordc on wordpress.
Here’s the problem.
You cannot link within a post to your technorati tag (worda+wordb+wordc) because wordpress will remove the + and you get wordawordbwordc
Not what you really want.
Let me see if I can make this clearer.
You may want to hyperlink keywords within the post but not leave your site and have no real post to link to, thus you would love to link to that tag, right? Well, to have that tag be equal to technorati you want to us a “+” between words, but you can’t do that in a wordpress link. WordPress will remove the +.
The only way to link keywords to a tag page in wordpress is to seperate words with a –
That’s the same way wordpress sees your tags, categories, and everything else. WordPress always uses – while technorati used a +
The only real way to stay on your site and use the + is to link the keywords to a search function (hyperlink like normal but end with index.php?s=wordsa+wordb” rel-“tag”) This will then cause a search function on your site for that tagged words in the hyperlink
This is a long way to say, on wordpress you will never have a tag “page” that is equal to a tchnorati tag because wordpress doesn’t allow the use of + as a separator between words.
CJs last blog post..Akismet Spam
Nicely done. Most of my blog ‘marketing’ is done through social bookmarking. (I use socialmarker.com to broadcast to multiple bookmarking sites at once.) I really like your ideas here.
Make Online Moneys last blog post..Profit from Poo
I’ll consider adding something like the tag cloud, but I really don’t like the look of it. I’d prefer it to show the more popular tags increasingly darker and darker, but the same font. Any chance you’ve seen one like this I could use?
Trying Hards last blog post..Preparing Safety Posts
Trying Hard – try installing the “Simple Tags” plugin, it lets you customise the appearance of tag clouds and do all sorts of other clever things with tags.
I’ll check that out. Thanks.
Trying Hards last blog post..Multiple Ideas Mashed Into One Topic
I am yet to see the benefit of using tag cloud. Maybe I’m wrong but for now I don’t like to clutter my sidebar with it.
Blog for Beginnerss last blog post..Yet Another 8 CSS Tips For Your Blog
Any reason why my web site would not be creating the tags on posts?
I added this as you suggested (it’s taken out now):
<?php the_tags(‘Tags: ‘, ‘, ‘, ”); ?>
I also tried adding the technorati tags plugin that’s still in there. If you look at the source you will see this:
So for some reason the template isn’t allowing the tags to go thru. If I use another template the tags show up…
Craig Mullinss last blog post..First Things First in Choosing Your Next Home
@Craig Mullins – If you use another theme and the tags show up then your theme is mis-coded. Search the WordPress forum for the answer, it probably doesn’t have the normal WordPress necessary calls – like the one in the footer most likely.