This unique WordPress hack will allow you to index tag pages you create without having to create template files for each and every one.

This post is part of 30 WordPress hacks in 30 days.

Back in WordPress Hack #15: Hacking WordPress Tags I described how to add “tag support” to your WordPress theme files, and how to add a “tag cloud” like the one I use on this blog in the bottom of the left sidebar. When you “tag” pages you are actually creating additional pages in your blog – that can get indexed by search engines.

For example, let’s say that I create a new post about an iPod. I put the post in the “gadget” category, and tag it “iPod” and “mp3 player”. Within the WordPress paradigm many things happen…

  1. A new post page is created based on your single.php theme file using the post title as permalink
  2. The post is added to the top of your blog home (usually your index.php home, unless you changed it – like I did)
  3. The post is added to the appropriate archive pages for day, month, year, etc.
  4. The post is added to all “category” pages you assigned it to
  5. The post is added to all “tag” pages you added it to

If you read WordPress Hack #18: WordPress Template Files, you already know that you can create custom “tag” and “category” pages, so when the old google crawler comes a-knockin’ it will find original content and not penalize your blog in search rankings. The problem normally is – if you’re a prolific blogger, you (like many of us) may have a few dozen categories, and hundreds (if not thousands) of tag pages.

When you categorize a post, you can find it within your blog at:
www.site.com/category/cat-name

When you tag a post you can find it within your blog at:
www.site.com/tag/tag-name

To create a custom page for any category or tag page, all you have to do is use your index.php or single.php to create a new WordPress theme file. Open either index.php or single.php in a text editor and “save as” either:

category-id.php (for category pages)
or
tag-slug.php (for tag pages)

This means if my “gadget” category was “17” then my theme file for it would be “category-18.php”. If my tag was “mp3 player”, then my theme file for it would be “tag-mp3-player.php”. View my WordPress Template Files hack page for pics and a better description.

So – What “I” did was create category theme files for every category I had. THEN, I created a single “tag.php” file that would display for every tag page I have. What I didn’t mention up until now was that if you create a “category.php” and “tag.php” file and put them in your theme directory that these will be used for ANY category or tag pages that don’t already have one for that slug or ID.

Every blog is of course a different topic (or niche), but this is what I did for tag pages on one blog I own. I used the tag title to create a different description lead-in sentence to get each tag page listed in the search engines. Right before “the loop” I placed this bit of code to do that:


! My blog is about geeky tech stuff, technology, Linux, gadgets, web tools, and more! , the posts below should be right up your alley!!

That code gets the “tag_title” and uses it like this (for the example “mp3 player”):

“This page is about MP3 Players! My blog is about geeky tech stuff, technology, Linux, gadgets, web tools, and more! If you like MP3 Players, the posts below should be right up your alley!!”

I did this a month ago on one of my blogs, and all the tag pages are indexing nicely! I’m sure you could hack this up even further – but this simple little solution fixed my tag page indexing problem quickly.