Make Big Money Online Top

How To Change the Way WordPress Displays Your Title

Written by George Manty  · June 22, 2006

One of today’s post by Darren Rowse of ProBlogger prompted me to figure out how to change the code on my blog so that my titles were more Search Engine friendly.

I have never liked the way wordpress displays the title by default. I wanted my blog to display only the title of the post in the title bar when you were on the post page. So I decided to change that.

NOTE: If you don’t know what the title tag is, go back and look at this post on my other blog.

To change the default title tag in wordpress you need to edit the header.php for the theme that you are using.

The line of code you want to change will look something like this:


<title>< ?php bloginfo('name'); ?> < ?php wp_title(); ?> </title>

Replace that code above with the code you want to use. Here is the code I am using on this blog (and will be soon using on all my blogs):

< ?php if(is_home())
{ echo '<title>'; echo bloginfo('name');
echo '< /title> '; }
else
{ echo '<title>'; wp_title(' '); echo '</title>'; } ?>

The code above displays the name of my blog as the title if you are on the home page. Otherwise, it only displays the post name if you are on a post page, the name of the archive page if you are on an archive page, or the category name if you are on category page.

It’s kind of funny how long it took it me to figure this out. I made it much more complicated than it needed to be. At one point the code looked like this:

< ?php if(is_home()) { echo '<title>';echo bloginfo('name'); echo '< /title> '; } else if ( is_category() ) {echo '<title>'; wp_title(); echo '</title>';} else if ( is_archive() ) { echo '<title>'; wp_title(); echo '</title>';} else { echo '<title>'; the_title(); echo '</title>'; } ?>

While it did the job, it was overkill.

Fortunately, I found the WordPress wiki and was able to quickly find the code changes I needed to make from there.

Another option for changing the way your title displays in WordPress is to use the Optimal Title WordPress Plug-in. But I prefer making the code change above.


AddThis Social Bookmark Button


Comments

5 Responses to “How To Change the Way WordPress Displays Your Title”

  1. Daniel Gattermann on July 6th, 2006 11:23 am

    Even simpler:
    < ?php is_home() ? bloginfo('name') : wp_title(''); ?>

  2. gmanty on July 6th, 2006 11:41 am

    I didn’t see your code, try again. You might need to use the wordpress code tags around your code to see the code.

  3. Daniel Gattermann on July 6th, 2006 12:08 pm

    I’ve already e-mailed George about it but here I try again:

    <title><?php is_home() ? bloginfo('name') : wp_title(''); ?></title>

  4. gmanty on July 6th, 2006 12:13 pm

    Great thanks,
    George

  5. Blogging Tips And Tricks on June 13th, 2008 6:10 pm

    I simply use All-In-One SEO Pack for WordPress to do this. Still, nice hack.





   _________________________________________________




Bottom