Nov 21 2006 at 4:24pm

Fixing my Wordpress Title Tags

Update 03/07/2008 – I am no longer using this solution for my title tags. Read more about my new solution in Fixing my wordpress title tags, revisited. The solution below may still be useful for anyone who finds the plugin options to be overkill.

I thought I’d document this just for my own info and in case anyone else is looking to do the same thing.

Default title format

The default wordpress titles look like this:

Home page: Blog Name (and that’s it)
Category Pages: Blog Name » Category
Archive Pages & individual posts: Blog Name » Blog Archive » Post Title

I wanted to reverse this for a few reasons. Firstly because it’s good for people that have a lot of tabs open and can only read the first part of the title. Secondly, it might be better for SEO and actual reading of SERP’s. Thirdly, because I just like it better that way.

My preferred format

This is how I like my title tags:

Home page: Blog Name – description
Category Pages: Category Name – Blog Name
Archive Pages: Post Title – Blog Name

The default code

The default code is in the header.php theme include and looks like this:

<title>< ?php bloginfo('name'); ?> < ?php if ( is_single() ) { ?> »
Blog Archive < ?php } ?> < ?php wp_title(); ?></title>

Step 1: Add conditional for home page

There are a couple of things I had to do. First, put in a conditional so that it generates different title tag for the home page. Then get rid of those » characters.

I started with a modification I found in this article on Perfecting Your WordPress Title Tags. This puts in a description for the home page and takes out the “Blog Archive” bit:

<title>
< ?php if (is_home()) { ?>
< ?php bloginfo('name'); ?> » < ?php bloginfo('description'); ?>
< ?php } else { ?>
< ?php wp_title(); ?> » < ?php bloginfo('name'); ?>
< ?php } ?>
</title>

If it’s the home page, put in the blog name and description. Otherwise, just use the title and blog name. The first problem I had with this is that when I copied the code it put in curly quotes around the php attributes which caused an error message. Make sure those are straight.

Step 2: Remove » separators

That still has the » characters so I replaced those with hyphens (when choosing a title separator, think about how a screen reader would read it. » reads “right double angle bracket”. No good. I used to like | but that is read as “vertical bar”. Also no good. A plain old dash or colon work best).

<title>
< ?php if (is_home()) { ?>
< ?php bloginfo('name'); ?> - < ?php bloginfo('description'); ?>
< ?php } else { ?>
< ?php wp_title(); ?> - < ?php bloginfo('name'); ?>
< ?php } ?>
</title>

Step 3: Arrange separators properly

The problem I had after this is that the »’s are built into the title. So I ended up with titles that looked like this: » Fixing my wordpress title tags – MeganJack.com. To remove those I had to consult this post on wordpress accessibility hacks. Scroll down about half way to find the part about Removing superluous fluff from being read aloud. There is a solution to removing the other » from the title tag: simply put a $sep=’blah’ value into wp_title().

The problem with this is that in that example the author did not rearrange the order of the title bits. The defined separator automatically goes in before the title text. So I just took it out altogether and entered in my dash between the title and the blog name.

The Optimal Title plugin solves this problem by changing the position of the separator to after rather than before the title. I thought about using it but decided it’s not worth cluttering things up with another plugin since my solution works fine.

Final Solution

Now my code looks like this:

<title>
< ?php if ( is_home() ) { ?>< ?php bloginfo('name'); ?> - < ?php bloginfo('description'); ?>
< ?php } else { ?>< ?php wp_title($sep = ''); ?> - < ?php bloginfo('name'); ?>
< ?php } ?>
</title>

If it’s the home page, put in the blog name then the blog description (my tagline). For all other pages, put in the title then the blog name, seaprated by a dash. That works for the category pages too. Perrrrrrfect :)

Update 16/12/2007: Added headings to clarify sections, inserted note about the optimal title plugin.

P.S. I am now in the process of removing the rel=nofollow from comment links. I think it’s kind of rude for people to do that to their commenters. Same with discussion forums. You’re doing me a favour by participating on my blog, the least I could do is give you a followable link (pathetic link value as it is!). Askimet catches most of the spam here so I’m not worried about that. We’ll see though :)

Update 16/12/2007: My current dofollow plugin only removes the nofollow for commenters who have already posted at least 3 times. If I’ve let a few of your comments stay up then you’re probably cool :)

Comments RSS

28 Responses to “Fixing my Wordpress Title Tags”

  1. Thanks for the amalgamation of info I think I will follow your example. I haven’t really looked too much into screen reader technology yet, so I had no idea about the length of reading ». I love how flexible WordPress is! It is great to be able to do everything in the theme or a plugin and not have to worry at upgrade time.

    :o )

  2. Hi!
    I just wanted to say thank you very much! I’ve been trying to figure out how to change the Title tag on my blog and this post has just helped me out enormously. Very clearly written. :-)

    Cheers again,
    Chris

  3. Thank you! Really clear instructions and a good idea. I’ve just put it into action at Storynory.

  4. This is a great idea and it’s really working, thanks! Most users appreciate your effort.

  5. Got here through Google search. Great fix you have here. I’ve implemented it.

    But you could make the final code a bit more obvious. I copy pasted the first code block before I realised you were improving it and had posted the final version at the end.

  6. Thanks, everyone! I’m glad you’ve found this useful.

    Marc – that’s a good point. I’ll add in some better headers when I get a chance :)

  7. Excellent post. I found this very useful! Thanks!

  8. Thank you so much for the tip.

  9. Hey –

    Thanks for this. My Wordpress upgrade broke a lot of stuff I didn’t remember how I’d done before. Your post was exactly what I was looking for.

    Excellent!

  10. Thank you that works very nicely indeed. I have been looking for a similar solution to negate the “>>’s”
    Very pink blog by the way.

  11. Awesome post, I’ve been looking for a good way to get rid of those >> symbols :)

  12. This is good advice. I’ll remember to incorporate this for Wordpress projects requested by clients.

    Thanks, Megan!

  13. Thanks for the tip Megan. I’ve been playing around with this like you without the results I wanted. I finally gave up and then searched for an answer. (Too proud to give up I guess). Glad I found you site.

  14. Thanks for your help Megan. I will bookmark your site forever.

  15. Megan I am very thankful of yours that you have this information. I did searched many website but didn’t get satisfy answer But after reading your post I could remove “Blog Archive” word from my wordpress blog title.

    Thanks

  16. Awesome tip, thanks.

  17. Great post Megan, i found this very useful even though i use Headspace already, it doesn’t always give you exactly the layout you want especially with the seperators.

  18. Thanks for this – great idea.

  19. I recently discovered this blog. I’ve had a similiar idea to your rewriting the ten commandments for some time now.

  20. Thanks for the post, I have been having the same problems.

  21. Keep up the good work! :)

  22. Thanks for this – great idea.

  23. Thanks for the post, I have been having the same problems.

  24. Thank you. This worked perfectly. =]

Leave a Comment


(will not be published) (required)