Better title for your blog pages

The default title of the blog pages in WordPress is awful. It’s so easy to make it look more user and SEO-friendly! It only needs one edit in the header.php file.

Default title

I checked one of my WP themes. When I opened the header.php file, I found between the title tags the code shown below:

This will show something like: blog_name » Blog Archive » the_title_if_article. As you can see it’s not very nice. It would be better if the page title were different for pages, archives, posts etc. Let’s do it!

Better title

First, open /wp-content/themes/{theme_name}/header.php and find the title tags: <title> and </title> and replace the line with:
<title><?php if (is_home () ) { bloginfo(‘name’); }
elseif ( is_category() ) { single_cat_title(); echo ” @ “; bloginfo(‘name’); }
elseif (is_single() ) { single_post_title(); echo ” at “; bloginfo(‘name’); }
elseif (is_page() ) { single_post_title(); echo ” - “; bloginfo(‘name’); }
elseif (is_search() ) { echo wp_specialchars($s); echo ” searching in “; bloginfo(‘name’); }
elseif (is_archive() ) { echo “Archives of “; bloginfo(‘name’); }
else { wp_title(‘’,true); } ?></title>

How does it work

Below I’ll show you how this works, as it would be implemented on this blog. The titles on your blogs won’t contain “Open WordPress” but your own blog title.

  • if (is_home () ) { bloginfo(’name’); } - this gives us the title for the home page which is the blog name. Here it would display “Open WordPress”.
  • ( is_category() ) { single_cat_title(); echo ” @ “; bloginfo(’name’); } - this is for category. When you browse plugins category on Open WP it would display: “Plugins @ Open WordPress”.
  • (is_single() ) { single_post_title(); echo ” at “; bloginfo(’name’); } - this is for single post. When displaying Welcome to Open WordPress! the title would be: “Welcome to Open WordPress! at Open WordPress”.
  • (is_page() ) { single_post_title(); echo ” - “; bloginfo(’name’); } - this is for pages titles. It makes it “page_title - blog_title” ie. About - Open WordPress”.
  • (is_search() ) { echo wp_specialchars($s); echo ” searching in “; bloginfo(’name’); } - this one is for search results. When you’re try to find anything about plugins and type “plugins” in the search box, the title is: “plugins searching in Open WordPress”.
  • And the last one: (is_archive() ) { echo “Archives of “; bloginfo(’name’); } while archives are displayed. This one shows: “Archives of Open WordPress”.

P.S.: I know that there are plugins to convert title but I prefer to do it this way :) What about your titles?

 
 
Comments

Well I tried your update, and it broke my wordpress :(

Dean said on February 16th, 2007 at 2:59 pm

EDIT: Replacing various parts makes it work..

Dean said on February 16th, 2007 at 3:04 pm

No way dude :D

Pausa said on May 9th, 2007 at 4:23 pm

Thanks, your tips does works without any problem. I use the is_category() ) { single_cat_title(); } code because my theme does not support category page.

heris said on September 14th, 2007 at 8:34 am

I did this.. but when I open an archive link, the archive or category name gets repeated with >> and -

Danny said on February 5th, 2008 at 9:37 pm

now my wordpress theme dosnt work… it says.. :-(

Parse error: syntax error, unexpected ‘@’, expecting ‘,’ or ‘;’ in /home/content/d/a/n/html/wp-content/themes/green/header.php on line 7

Danny said on February 5th, 2008 at 9:39 pm
Leave a comment