How to: Redifine title tag with a custom field

January 30, 2009 at 8:25 am

Some time ago, I shown you how to make your title tag SEO friendly. Even if it is already cool, this function can still be enhanced by using a custom field. Read on if you’re interested.

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() ) {
    $customField = get_post_custom_values("title");
    if (isset($customField[0])) {
        echo $customField[0];
    } else {
        single_post_title();
    }
} elseif (is_page() ) {
    bloginfo('name'); echo ': '; single_post_title();
} else {
    wp_title('',true);
} ?>
</title>

Then, if you want to define a custom title tag, simply create a custom field named title, and give your title as a value.

Tags: