April 4, 2010

Add a Title to Your Blog Homepage in WordPress

I came across an interesting problem. When you create a WordPress site and your blog page is you home page, there is no editable page in your administration dashboard. Normally, your title tag in WordPress looks like this:

<title>
    <?php wp_title('&laquo;', true, 'right'); ?> 
    <?php bloginfo('name'); ?>
</title>
 
/*
* This Generates:
* <title>
*     Your Blog Name
* </title>
*
* when you are at you home page. And:
*
* <title>
*     Your Post Title « Your Blog Name
* </title>
*
* when you are on a post page
*/

The problem is that wp_title() doesn’t have any title to return because your blog page isn’t an editable page in your dashboard. Here is a small hack to get it to work. You will need to make sure to fill out your tagline in Administration->Settings->General->Tagline. This input will act as your title.

<title>
    <?php if (is_home()) : 
        bloginfo('description'); 
        echo " &laquo; "; 
    else : 
        wp_title('&laquo;', true, 'right'); 
    endif;?> 
    <?php bloginfo('name'); ?>
</title>
 
/*
* This Generates:
* <title>
*     Your Tagline Description « Your Blog Name
* </title>
*
* when you are at you home page. And:
*
* <title>
*     Your Post Title « Your Blog Name
* </title>
*
* when you are on a post page
*/

Leave a comment