milotitles1

The title of your page (The few words in the very top bar of your browser window)  is arguably the most important thing search engines look at as they decide where to rank your page.

Most themes come with a very basic title set up; the name of your post and the name of the blog. It works well enough on regular post pages, but what about search pages, archives, 404s and all the others?

And some of these will be much more useful to your readers as well. We all know how helpful it is to open up 6 different tabs on one website only to find that they all start with the site’s name. Doesn’t help you keep track of all the pages you’ve opened very much.

The code below can be copied and pasted directly into your blog to create different titles for all the different types of page.

The New Titles

Below I have listed the new formats the titles will take for each of your pages (The actual title used on the page starts after the – ).

  • Home Page – Blog Name | Blog Description
  • Search Results – Search Results for search terms11 Articles | Blog Name
  • 404 (Error) Page  – Blog Name | 404 Nothing Found
  • Author Archives – Blog Name | Author Archives
  • Single Post – Post Name | Category Name | Blog Name
  • Page – Page Name | Blog Name
  • Category Page – Category Name | Category Description | Blog Name
  • Monthly Archive – Blog Name | Archive | Month, Year
  • Day Archive – Blog Name | Archive | Month Day, Year
  • Tag – Tag Name | Blog name

How to Add To Your Blog

Open your theme’s header.php file and look for the line starting with .

In the default theme, it will look like this:

<title><?php wp_title('&laquo;', true, 'right'); ?> <?php bloginfo('name'); ?></title>

Now delete this line and replace it with the following:

<title> <?php if ( is_home() ) { ?><? bloginfo('name'); ?> | <?php bloginfo('description'); ?><?php } ?>
<?php if ( is_search() ) { ?>Search Results for <?php /* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(''); echo $key; _e(' &mdash; '); echo $count . ' '; _e('articles'); wp_reset_query(); ?><?php } ?>
<?php if ( is_404() ) { ?><? bloginfo('name'); ?> | 404 Nothing Found<?php } ?>
<?php if ( is_author() ) { ?><? bloginfo('name'); ?> | Author Archives<?php } ?> 
<?php if ( is_single() ) { ?><?php wp_title(''); ?> | <?php 
$category = get_the_category();
echo $category[0]->cat_name;
?> | <? bloginfo('name'); ?><?php } ?>
<?php if ( is_page() ) { ?><? bloginfo('name'); ?> | <?php 
$category = get_the_category();
echo $category[0]->cat_name;  ?>|<?php wp_title(''); ?><?php } ?> 
<?php if ( is_category() ) { ?><?php single_cat_title(); ?> | <?php $category = get_the_category(); 
echo $category[0]->category_description; ?> | <? bloginfo('name'); ?><?php } ?> 
<?php if ( is_month() ) { ?><? bloginfo('name'); ?> | Archive | <?php the_time('F, Y'); ?><?php } ?>
<?php if ( is_day() ) { ?><? bloginfo('name'); ?> | Archive | <?php the_time('F j, Y'); ?><?php } ?>
<?php if (function_exists('is_tag')) { if ( is_tag() ) { ?><?php single_tag_title("", true); } } ?> | <? bloginfo('name'); ?>
</title>

For anyone who has meddled with their theme’s code a little before, you will see that the code above is (for the most part) fairly simple. You can chop and change as you like if a different style of title would suit your blog better.

What do you do for the titles on your blog? There are some great plugins out there to let you specify custom titles for each post, but is that too much hassle to update regularly?

milo WordPress Hacks Series: The code in these posts was written entirely by Milo, a web designer from Oxford, Britain. Check out her website for free WordPress themes and her blog, or follow her on Twitter!

Enjoy this post? You should follow me on Twitter!