Post Pic

How to: Make your title tag SEO friendly

You know it: SEO is a very important part of your blog because without a good seo, you’re loosing lots of potential visitors. In this recipe, I’m going to show you how to optimise the <title> of your blog for a better SEO.

Open your header.php file for edition. find the <title> tag, and replace it by the following code:

<title>
<?php if (is_home () ) {
    bloginfo('name');
} elseif ( is_category() ) {
    single_cat_title(); echo ' - ' ; bloginfo('name');
} elseif (is_single() ) {
    single_post_title();
} elseif (is_page() ) {
    bloginfo('name'); echo ': '; single_post_title();
} else {
    wp_title('',true);
} ?>
</title>

This code will generate title tags according to the following model:

  • If the visitor is on the blog homepage: We'll display the blog name.
  • If the visitor is on a category page: We'll display the category name and the blog name.
  • If the visitor is on an article page: We'll only display the article title.
  • If the visitor is on a static page: We'll display the blog name, and the page title.

The result of this recipe can be seen on WPRecipes as well as on my other blog Cats Who Code.

Leave a Comment

* Name, Email, Comment are Required