Getting post page title from custom meta boxes is overwriting home page title?

I wrote the following function in WordPress:

function custom_meta_title($default) {
global $post;
$meta = get_post_meta( $post->ID, 'meta_title', true );
if ($meta == '') {
    echo $default;
    } else {
        echo $meta;
    }
}

And here is how I call it in the header.php file:

Read More
<title><?php custom_meta_title('A default title tag'); ?></title>

When you create a new post, there is a meta box where you enter the page title for SEO purposes. If you leave it blank, a default page title is displayed instead. When you are on the home page, the default page title is shown.

However, I just discovered that the home page isn’t showing the default title like it should; instead, it’s showing the title tag of the most recent post. Any idea what could be causing this or how I can fix it?

Related posts

Leave a Reply

1 comment