Oct
28
2008

How to Modify Your WordPress <title> Tag for Search Engine Optimization


Search engine optimization is one of the more important things, if not the most important, when it comes to your website. Sure, the way it looks and work are both important, as well as the content, but if Google or Yahoo can’t index your pages properly due to the fact that your site isn’t optimized then all that work is for nothing.

There are a few plugins available for WordPress that help with search engine optimization but I’ve found that they don’t allow you to really control all the elements you would want to plus I prefer to hard code certain things, just in case the plugins don’t work with updated versions of WordPress.

The following is a very simple change to perform, but in my opinion, is extremely important for every WordPress install.

Setting up your <title> tag to work dynamically

Whenever you create a web page, you must give that page a name. That is what appears at the top of your browser window.

In the header.php file of your WordPress theme you will come across a bit of code that looks something like this.

<title><?php bloginfo('name'); ?> <?php if ( is_single() ) { ?> &raquo; Blog Archive <?php } ?> <?php wp_title(); ?></title>

What this piece of code does is grab the name of your blog and use it for the title of your web page. You control this info by going to your wp-admin panel => Settings => General.

If you are on the main page of your website, you will see the name of the blog at the top of the browser but if you are on on a post’s page then you will see your blog name, “Blog Archive” and then the title of the post.

The basic problem with this default code is that the name of your blog always comes first. Is the name of your blog the most important information or is it the name of your post? Hopefully you said the name of your post.

So, the solution is pretty simple. Let move some things around until we get something like this.

<title><?php if(is_home()) { echo bloginfo(‘name’); echo|; echo bloginfo(‘description’); } else { echo wp_title(|, false, right); echo bloginfo(‘name’); } ?></title>

The first thing we’re doing here is checking to see if it is the home page. If it is then we’re going to show the blog name and then the tag line (see image above on where to go to change this), separated by a ” | ” character. You can change this to whatever you want but remember to leave the blank spaces before and after the character you choose. Next, if it is not the home page, we are going to show the name of the post (wp_title), but only if there is one. That is what the false parameter is gonna check for us. If there isn’t one then it will just show the blog name. But if there is one then it will show the post name then the blog name, separated once again by a ” | ” character.

Check back for more search engine optimization tutorials and tips.

You can get more information on the WordPress tags used here by going to the WordPress Codex page.

If you liked this, please share it.

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Short URL: http://bit.ly/djPIXc

Discussion 57 Comments

  1. antiquarian books on December 11, 2008 at 1:18 pm

    Thank you for this information. :)

  2. SEO on January 17, 2009 at 12:54 am

    Really a great plugin. I have used some similar ones in the past but this one is the best.

  3. 800 ready java scripts on February 9, 2009 at 2:23 pm

    your blog is great thanks for the info

  4. stockings on February 13, 2009 at 10:04 pm

    This is a very smart way. Sometimes plugin doesn’t do what it is suppose to be doing, it creates duplicates which confuses you even more. Thanks for the great info.

  5. blog for boys fashion on February 24, 2009 at 12:14 am

    Amazing information and Pleasure to read this.

  6. Searchgo on April 18, 2009 at 4:23 pm

    Thanks great post.

  7. Wayne- Home Business Opportunities on April 27, 2009 at 5:51 pm

    Thanks very much for the great information. I’m new to writing any sort of code, and had been looking for a way to have my site’s homepage and other pages display diferent title text. Been able to do that now thanks to your instructions, and my title bars look much more professional now as well as displaying how I want them to. Cheers!

    Wayne

  8. nimbrung.net on April 29, 2009 at 5:32 am

    This is useful tutorial to change wordpress title or you can following url below to know how to modifying it

    http://codex.wordpress.org/Template_Tags/wp_title

  9. Ernan on May 20, 2009 at 12:39 am

    Right on the spot. I tried to use All in One Seo and even Platinum SEO to do the work but it aint easy. Your post solved it all. Thanks.

  10. Genesis Pure Business Opportunity on May 22, 2009 at 3:08 am

    I am using the All in Once SEO Pack..hmmm, I think I’ll give this one a try…Thanks for sharing the info :)

    And keep up the good work here on your blog and remember that success is not by chance, it is by CHOICE!

    Cheers,
    Vanessa

  11. Pet Snakes on May 27, 2009 at 10:06 am

    Love your writing style and the design of your blog, its very original! Well done, look forward to reading more.

  12. Em Howes on May 29, 2009 at 10:32 am

    Thanks for this WordPress tutorial. I am so glad I found it. It is easy to understand and fun to read.

  13. freecalls on June 4, 2009 at 5:20 pm

    If you see here in blow header.php code. When i open any single post it shows me on top “Single post | Blog name” but just want “Single post” on top nothing else. What should i do?

    here is a few lines from header.php:

    <?php if (ishome () ) { bloginfo(‘name’); }
    elseif ( is
    category() ) { singlecattitle(); echo ‘ – ‘ ; bloginfo(‚Äòname‚Äô); }
    elseif (issingle() ) { singleposttitle();}
    elseif (is
    page() ) { singleposttitle();}
    else { wp_title(‘’,true); } ?>

  14. Blain on June 6, 2009 at 11:43 am

    What a great site for info, I am a novice, The info gained here I can put in my log and reuse in time.Thank youOur site please check us out

  15. c.bavota on June 11, 2009 at 12:11 pm

    This is a custom theme I have designed. My RSS button is directly underneath the big red “B” in the top left.

  16. Watch Year One on June 20, 2009 at 3:43 pm

    After reading the article, I feel that I need more information on the topic. Could you suggest some more resources ?
    p.s. Year One is already on the Internet and you can watch it for free.

  17. Gene on June 27, 2009 at 7:47 pm

    I was searching for a modification tutorial, thanks for keeping it simple for an old guy like me!

  18. Jan-Olov on June 28, 2009 at 9:40 am

    If your main keyword is in the name of your company or business and it is included in the title tag, if you the register your site with Google Local Business Center you are likely to find you rank better for your keywords.

  19. High quality handbag store on July 2, 2009 at 7:47 am

    We offer high quality lady’s and men’s handbags. Free shipping for all. More then 30% discount. 40% cheaper then the market. But we made the best goods. Welcome to our website!

  20. Matt-Serfaklar on July 29, 2009 at 7:27 pm

    Great idea, but will this work over the long run?

  21. Mitch on August 3, 2009 at 12:54 am

    Love it. I didn’t want the title of my site on article post pages. So I removed echo bloginfo(‘name’);

    Thanks!

  22. Yan on September 16, 2009 at 11:20 am

    Thank you. This is exactly what I was looking for

  23. oes tsetnoc on September 18, 2009 at 8:09 am

    Hi! I was searching similar to your tutorial and stumbled with your site. Nice detailed information you have put in there. Thanks for sharing your knowledge.

    I could use this on my newest blog oes tsetnoc

  24. Nick Cordell on September 19, 2009 at 12:55 am

    Great info. I totally agree that the title of a particular post is most important. You taught me something new. Thanks

  25. zerg on September 22, 2009 at 5:05 pm

    Hi! Thanks you for nice post

Leave a Reply

Your email address will not be published. Required fields are marked *

*


To enter code in the comment box, please place it between <pre lang="php"> </pre> tags. You don't have to convert any characters to their hex/HTML code. Just add your code the way you would to any code editor.