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.

26 Responses

Dec 27 2008 12:42

The wpSEO Plugin makes it automatically.

Dec 27 2008 15:28

I use the “All in One SEO” plugin which let you do this and a lot of other valuable stuff. Secondly I would recommend that before you use any of these things you do a little study on SEO to make sure you’re targeting the right keyword terms.

Dec 27 2008 17:18

I also use All in One SEO pack, but this article is very good for those who want to make a SEO WP Theme :)

Best regards,
Chris

Dec 27 2008 17:32

But why use a plugin when you can do it so simply and elegantly like Jean-Baptiste has it?

Plugins eat up memory, and if you’re on shared hosting you have to watch things like resource usage.

Jean-Baptiste, thank you for publishing this. The SEO plugins have been too bulky for my taste, and this will do the job beautifully. Already added to my header. Thank you again.

Dec 27 2008 17:39

There’s a lot of good and complete SEO plugins, that’s a sure thing! But in my opinion this recipe is useful for the following reasons:
1) As Plurkr said, if you’re a theme designer, it’s always better to use a SEO-friendly title, even if the user can use a plugin which will do the same job.
2) As Sue said, if you have lots and lots of plugins, your blog can load slowly. Also, sometimes you just need one feature from a plugin, not all the options.

Glad to see that you liked this recipe anyways :)

Dec 27 2008 17:49

I agree that all points are valid and the way to go ahead depends on your purpose and situation. But understanding SEO will still be a requirement to get things right as this recipe might be great if you have though SEO into naming categories etc. of your blog but if you didn’t then you’ll not get the full benefit.

Dec 27 2008 17:59

Thanks a lot guys, but i have a plugin for the same thing :D

Regards.

Dec 27 2008 18:26

Here is another, with a bit more complex coding.

<title>
<?php if ( is_home() ) { ?><?php bloginfo(‘name’); ?>&nbsp;|&nbsp;<?php bloginfo(‘description’); ?><?php } ?>
<?php if ( is_search() ) { ?><?php bloginfo(‘name’); ?>&nbsp;|&nbsp;Search Results<?php } ?>
<?php if ( is_author() ) { ?><?php bloginfo(‘name’); ?>&nbsp;|&nbsp;Author Archives<?php } ?>
<?php if ( is_single() ) { ?><?php wp_title(”); ?>&nbsp;|&nbsp;<?php bloginfo(‘name’); ?><?php } ?>
<?php if ( is_page() ) { ?><?php bloginfo(‘name’); ?>&nbsp;|&nbsp;<?php wp_title(”); ?><?php } ?>
<?php if ( is_category() ) { ?><?php bloginfo(‘name’); ?>&nbsp;|&nbsp;Archive&nbsp;|&nbsp;<?php single_cat_title(); ?><?php } ?>
<?php if ( is_month() ) { ?><?php bloginfo(‘name’); ?>&nbsp;|&nbsp;Archive&nbsp;|&nbsp;<?php the_time(‘F’); ?><?php } ?>
<?php if (function_exists(‘is_tag’)) { if ( is_tag() ) { ?><?php bloginfo(‘name’); ?>&nbsp;|&nbsp;Tag Archive&nbsp;|&nbsp;<?php single_tag_title(“”, true); } } ?>
</title>

—Frosty @ WPCult

Dec 27 2008 20:51

curiosity: what do you think is better to use for the single_page?

1) post title
2) post title | blog name

For example I prefer using the first version – only the post title…

Dec 27 2008 22:26

@Plurkr,

I would always go for the post title and leave out the blog name. And the reason it two-fold:

1) You need to construct your post title for optimum SEO usages (that includes conversions so that people seeing it in the search engine result will want to click it).

2) Unless you’re trying to build a brand (with the name of your blog) it will not help you achieve anything. The more text in the title the less each word will “mean”.

Dec 27 2008 22:40

@Agolf Cartson another reason to only use the post name is for the case in which a user adds the post to a Social Bookmarking Service [eg: del.icio.us]

In my opinion it’s “ugly” to see the blog name in the end of the link.

So, I totally agree with you: “Unless you’re trying to build a brand (with the name of your blog) it will not help you achieve anything”

Dec 27 2008 23:34

I use only posts titles. What Plurkr said about social bookmarking is true, and also this is the same with google search results.

Jan 09 2009 10:33

Great, simple way to do this without the need for a plugin, I personally am trying to trim the resource demands of my wordpress blog, and tricks like this will help.

Jan 09 2009 16:11

-So, I totally agree with you: “Unless you’re trying to build a brand (with the name of your blog) it will not help you achieve anything”

I disagree. For starters if your website is johns blog at johns-blog.com and your website is about blogging. The title will hold allot of wait. Kind of 1 and 1 million odds of that though.

But the reason I tend to add my site name is, studies have shone people are more likely to click on a link if they know where it’s heading. Nobody wants to click on “FREE EBOOKS”, but
if it were “FREE EBOOKS Johns Blog” – less likely to be a garbage site.

Last pointer, not to drag this on, NO search engine will dock you any amount of ranking for adding your site name to the title, Nor will it dilute any of your keyword/phrase weight by enough to matter. Go to any SEO site, they will all recommended doing this. Trust me it’s what I do for a living! hehe.

Jan 10 2009 00:22

cool, i’ll be sure to use this on my site :)

Jan 16 2009 13:16

Wow….

That’s very Usefully…

Apr 30 2009 13:32

Hi,

I have a wordpress blog and I have enabled tagging. But I see that when i hover the mouse on the tags which is placed on the right side bar, i see the path as: http://blog/tag/tag-name
here the /tag after blogname and before the actual tag starts.

This is the value that it sets by default if there is no entry in the TAG_BASE. But I don’t want this /tag/.
can anyone help me with this.

May 11 2009 10:46

for title tags we also had a plugin seo custom title where we can add out title customly

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required