The Wordpress Title Tag: In Search For a Perfect Solution

In the world of SEO the title tag really is king, not to mention the fact that users see the title tag as the label to their bookmark. Because of this, a developer must spend much time making sure the title tag is well formed.

Luckly, the user’s mind and a search engine work very similarly to each other. The first words are the most important, and often the only ones looked at. Because of this, the true nature of your content must be first in the title tag. For pages this is the title of the page, for posts, the title of the post, and for my home page, a place where there is a hodge-podge of information, I decided it should be my name (so I actually show up in search results for my name). This means I have to first write a bit of PHP code to distinguish these different types of situations, and print some info in the title tag for each of them. Here is what I came up with:

<title>< ?php if(is_home()) print "Dan Bowling's"; ?>< ?php wp_title(''); if(!is_home()) print " at";?> < ?php bloginfo('name'); ?> < ?php if ( is_single() ) { ?>'s blog archives < ?php } ?> </title>

So, while using Wordpress, if it is the frontpage, it will output “Dan Bowling’s”, followed by the blog name, since the front page has no title. Resulting in a title tag that says “Dan Bowling’s northlander.org.” Great, that is just what I want people to think of when they hit my homepage. I made it so the home page doesn’t display “at” between “Dan Bowling’s” and the site title with a simple if not statement of if(!is_home()) print “at”.

If it is a page, the first if statement is false (since it isn’t the home page), and it is skipped. Then we get “the page title” + “at” + “site name”, such as “Services at northlander.org”

On a post, things work out just as well, adding an extra bit of info claiming it is a blog archive. For instance, this post would read as “The Wordpress Title Tag: In Search For a Perfect Solution at northlander.org’s blog archives”

All this is made possible by simple if statements, that serve a slightly different form of the title tag to each page served, depending on the type of page… all from the same header code.

This kind of simple implementation could be used on any wordpress blog easily, simply by changing the part with my name. Other nifty things to include might be the tagline, whcih can be gotten using the bloginfo(’tagline’) function in WordPress.

If you are a blogger, do you use the default for your platform, or do you mix it up a little?

Leave a Reply