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.

Also note that this code was posted in 2006 and may not be compatible with current versions of WordPress.

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

49 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. =]

  25. Thank you very much for the .php code you have provided in your post. I’ve been searching for this topic when i bumped into your article. It’s really a big help for me.. :)

  26. Good Post .Titles are rather easy to change however its will be a painstaking effort to change the header with a logo

  27. Thanks for sharing this post about WP and the codes. It was very helpful and informative! Cheers!!

  28. Thanks for the info. I finally got rid of the unnecessary “Blog Archive” label in the title of each post. Very helpful. This was much more straightforward than the HeadSpace plugin for all I needed to do.

  29. Hi:
    This method is not worked for me, my blog title still showing the default website tag line with my title.

    I am using all in one SEO plug-in to control my description tag and keyword tag , i didn’t used this plug-in for custom title for my blog posts .

    I have analyzed the code but this problem still exists!

  30. Sorry i have forgot to mention
    The title tag is generated through wordpress core file not from ALL in one SEO plugin only the keyword tag and description tag is controlled by that plug in.

  31. Hi Sakthi,

    Did you try turning off the SEO plugin? I’m not familiar with that plugin but if it has the option to do your title tags then it might be still overriding them with the default, even if you have that option checked off. That’s the only thing I can think of… unless there’s some other plugin interfering with the template code.

  32. Hi:

    Finally its worked!

    Before making this changes my title was looked like this

    Best Working Adsense Optimization Tips|sakthiganesh.com-online money making blog

    after doing this configuration the post title is now looking

    Best Working Adsense Optimization Tips

    The problem is misconfiguration i have done with the ” All in one SEO Plug-in ”

    The default option present in the
    “Page Title Format =%post_title% | %blog_title%”

    should be changed to

    “Page Title Format =%post_title% ”

    Thanks Megan as you have said ,the problem lied with the default setting override by that plug-in and now its working perfect

  33. Thanks for the clear explanation. I was just about to go looking for that wp_title() function to get rid of the separator when I found this page. Now I won’t need to. :)

  34. cool!!!)

  35. Thanks for the explanation, I am having rather difficult time trying All In One Seo doing the job I want. I’d better turn it off and try the code here

  36. Hi Megan,

    I`m a bit hopeless with all this business, and I had my work done with the SEO plugin, but no matter what I do – google webmasters tool is telling me than my homepage is missing a title tag. I`m going crazy! I`ve read a zillion websites, but they are all spanish to me. Help! thanks…

  37. Oh, all fixed now!

  38. Hi Megan. Thanks for sharing. I’ve just bookmarked it in Delicious. I am sure I will reference it again. :)

  39. I’m glad I could be of help!

  40. Loving the post; figured out how to do this ages ago… But then again, i might have trawled through your post and been given the idea.

    Anyways,
    Thanks,
    Michael Swan
    I.T Technician

  41. Intresting post, i really enjoyed reading it.

  42. Hello.
    I the first time here.
    The exclusive is assured it of 100 %,news Video

    http://kirstendunst-nude.blogspot.com

  43. all these days i was so frustrated of >> just before the title……didnt find a sngle post abt gis…..thanks gudness for ut post my title is clean now without the >>s :-)

  44. I’ve been “encouraged” by my fellow executives at Netconcepts not to do any programming. But it does make the title tags across your WordPress site or blog a It always repeats the title twice.

Leave a Comment


(will not be published)