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



Adam November 21st, 2006 at 10:50 pm
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.
Chris December 20th, 2006 at 2:54 pm
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
Bertie May 2nd, 2007 at 4:12 pm
Thank you! Really clear instructions and a good idea. I’ve just put it into action at Storynory.
kichler lighting May 23rd, 2007 at 6:34 am
This is a great idea and it’s really working, thanks! Most users appreciate your effort.
Marc June 3rd, 2007 at 4:53 am
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.
Megan June 3rd, 2007 at 7:12 pm
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
Kent Schnepp June 11th, 2007 at 3:09 pm
Excellent post. I found this very useful! Thanks!
Vincent Winterbourne June 18th, 2007 at 11:12 am
Thank you so much for the tip.
Murphy June 27th, 2007 at 11:19 pm
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!
Angling August 18th, 2007 at 1:15 pm
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.
Devindra February 18th, 2008 at 2:06 pm
Awesome post, I’ve been looking for a good way to get rid of those >> symbols
Bryan March 13th, 2008 at 9:14 am
This is good advice. I’ll remember to incorporate this for WordPress projects requested by clients.
Thanks, Megan!
Tom April 13th, 2008 at 7:05 pm
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.
Valerie May 2nd, 2008 at 7:52 pm
Thanks for your help Megan. I will bookmark your site forever.
Seo Tips July 5th, 2008 at 7:30 am
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
Dave Child July 22nd, 2008 at 3:14 pm
Awesome tip, thanks.
Justin Hayward September 22nd, 2008 at 7:00 am
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.
dragoc2099 November 5th, 2008 at 7:13 am
Thanks for this – great idea.
suzancrain November 11th, 2008 at 6:03 pm
I recently discovered this blog. I’ve had a similiar idea to your rewriting the ten commandments for some time now.
fredydeath November 12th, 2008 at 4:26 pm
Thanks for the post, I have been having the same problems.
olegskazka November 17th, 2008 at 6:18 am
Keep up the good work!
mattnel33 November 17th, 2008 at 3:47 pm
Thanks for this – great idea.
nicsmr November 23rd, 2008 at 5:45 am
Thanks for the post, I have been having the same problems.
Oyun Hileleri May 23rd, 2009 at 12:30 pm
Thank you. This worked perfectly. =]
Hublon July 14th, 2009 at 8:24 pm
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..
Seven Jeans August 7th, 2009 at 5:16 am
Good Post .Titles are rather easy to change however its will be a painstaking effort to change the header with a logo
Lyndon August 26th, 2009 at 12:48 pm
Thanks for sharing this post about WP and the codes. It was very helpful and informative! Cheers!!
Craig T. October 5th, 2009 at 8:43 am
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.
Sakthi Ganes October 7th, 2009 at 12:38 pm
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!
Sakthi Ganes October 7th, 2009 at 12:40 pm
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.
Megan October 7th, 2009 at 3:04 pm
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.
Sakthi Ganesh October 11th, 2009 at 11:37 pm
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
Robert November 11th, 2009 at 1:03 pm
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.
гур газ 3110 December 1st, 2009 at 3:14 am
cool!!!)
Fashion Diva December 30th, 2009 at 5:30 pm
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
Tibz February 12th, 2010 at 9:18 am
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…
Tibz February 12th, 2010 at 10:12 pm
Oh, all fixed now!
Dhany March 15th, 2010 at 1:13 am
Hi Megan. Thanks for sharing. I’ve just bookmarked it in Delicious. I am sure I will reference it again.
Megan March 15th, 2010 at 12:01 pm
I’m glad I could be of help!
Michael Swan March 21st, 2010 at 3:41 am
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
John Sam April 24th, 2010 at 6:57 pm
Intresting post, i really enjoyed reading it.
Nelfclige July 7th, 2010 at 11:44 pm
Hello.
I the first time here.
The exclusive is assured it of 100 %,news Video
http://kirstendunst-nude.blogspot.com
Deepanshu April 18th, 2011 at 7:10 am
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
admissions essay August 10th, 2011 at 11:59 am
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.