Performancing Metrics

Format Headline Title Tag To Attract Readers

Blog World has an article about attracting readers with your headline. One of the suggestions the author makes is in the way the <title> is used.

Take a look at the page titles on this site. Notice that the headline of the post comes before the name of the site. Thats deliberate. I added a WordPress plugin specifically to do that. Why? Because readers really don’t care what the name of the site is. They want to know what the post is about. The same is true for people who come across this page in a search engine.

That makes sense to me so I created a <title> tag that shows the name of the site and then the site description when on the home page, but when on a single article page, display the article title, then the site name. The author of this article used a plugin to accomplish this but all that is needed is some simple PHP and a slight hack.

First I created the <title> tag like so

        
<title>< ?php if ( is_home() ) { ?>< ?php bloginfo('name'); ?>&nbsp;< ?php bloginfo('description'); } if ( is_single() ) { ?>< ?php wp_title(' '); ?>&nbsp;by&nbsp;< ?php bloginfo('name'); } ?></title>

Note: WordPress adds a space between < and ?php so be sure to eliminate that space when copying the above into your header.php or index.php.

This puts the name of the blog and then the description in the title tag when the visitor is on the home page. When a visitor goes to a single page the title of the article is first followed by the name of the blog. The only caveat I found is WordPress by default adds some formatting to the bloginfo(‘name’); tag which really should be left to the user to format so I went into templates-functions-general.php and on line 130 I changed

$sep = '&raquo;', to $sep = '&nbsp;',

The above hack is not needed as Andy Skelton pointed out in the comments. I changed the <title> code below to reflect the change.

Now I have a <title> tag as the author suggests. I tried to follow the authors other suggestions in creating the headline for this article.

Update: I forgot about page.php and other template pages when creating the above title code. Here is the updated code

<title>< ?php if ( is_home() ) { ?>< ? bloginfo('name'); ?>&nbsp;< ?php bloginfo('description'); } else { wp_title(' '); ?>&nbsp;by&nbsp;< ? bloginfo('name'); } ?></title>

Categories: Blogging Sense

This post was written by . You can visit the for a short bio, more posts, and other information about the author.

Comments Closed

Comments

  1. Andy Skelton says: 3/30/2005

    Thanks! Great tip. There is a way to do it without editing the WP core: add the empty string as an argument for wp_title:
      by 

  2. Andy Skelton says: 3/30/2005

    Oops, my code segment got chopped. Let me try again:
      by 
    Just change wp_title(); to wp_title(''); and it will get rid of the raquo without editing the WP core. Cheers!

  3. John says: 3/30/2005

    Oh! Thanks Andy! While I was writing this up I actually had a quick thought that perhaps something like this would work but I was too lazy to follow up. Thanks again. I have updated the code above to reflect the changes.

  4. Ozh says: 3/30/2005

    What’s the difference with this and the old stuff Optimal Title ?

  5. Elegantly says: 3/31/2005

    It’s not a plugin, but a simple change to the template you’re using. In addition, it is far more likely that updated WordPress versions will break a plugin than a template.

  6. Mathias Bynens says: 3/31/2005

    Cool! I had been using a homegrown function for title tag handling, but now if I’d just port my non-blog content to WordPress Pages I can just use this code. I have a preferation for the pipe (‘|’) as a separator.

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

    Thank you.

  7. N. says: 3/31/2005

    Doesn’t look right when doing a search. Viewing Categories and months look kind of weird too, in my opinion.

  8. markku says: 3/31/2005

    I use the “post_title | weblog_name” format just as Mathias implemented it. Works quite well.

  9. John says: 3/31/2005

    Yeah, search results and months suck. I think the category title is fine. It’s easy enough to fix with another if else statement to account for those views. I’ll work on it later.