Hard-coding an SEO friendly title in the WordPress header file
November 12, 2007 – 4:48 am | byThe title I am referring to here is the title that appears in the top bar of your browser, and is in betweeen <title></title> tags in your code. Apparently, to make it more SEO friendly, the title of the post or article should appear before the title of your blog, but generally themes have it programmed the other way around.
You can switch it through the use of plugins, but if you want to avoid using another plugin you can fix this in the header.php file. Find the code that starts with <title>, and replace what is currently there with this:
<title><?php if ( is_single() ) { ?> <?php wp_title(''); ?> » <?php } ?><?php bloginfo('name'); ?></title>
This tells WordPress that if the page is not single, the name of the blog will appear only. This is for the homepage. If the page is single, i.e. a single post page, then the name of the post will appear and then the blog title. So, for example, a post on WordPressGarage would have the following title:
Yet another way to feed your facebook obsession ยป WordPressGarage



5 Responses to “Hard-coding an SEO friendly title in the WordPress header file”
By Anna Vester on Nov 12, 2007 | Reply
Wow, that’s pretty powerful. Thanks for this!
By Ryan on Nov 12, 2007 | Reply
I prefer my pages to show up in the same way as you have your single posts setup, so I use a different method. The text in this is probably going to goof, but I’ll try anyway …
<title><?php wp_title(' '); if(wp_title(' ', false)) { echo ' | '; } echo 'New Zealand Hockey | '; bloginfo('name'); ?></title>My site at http://flytrapgrowing.info/ uses this method if you want to see it in action.
By Ryan on Nov 12, 2007 | Reply
One more thing. Why the heck do theme designers do their titles the way they do? Nearly everyone agrees that the way you are suggesting here is better, but yet theme designers still continue to use the same system as the default Kubrick theme. It seems nonsensical to me. Or maybe I’m missing something?