WordPress Title Trickery

Here is a bit of the code we’re using on a new site redesign. We needed a custom, more descriptive title on certain pages.

It grabs a title from a custom field if you set one, or just gets the page title if you don’t. Also, since WP doesn’t display the page’s title if you’re on the homepage, we’ll grab custom text from the site’s description (which we don’t use for anything else).

<title>
<?php 
	$sep = ’ | ‘;
	$site = get_bloginfo(‘name’);
	
	if(!$title = get_post_meta($post->ID, ‘title’, TRUE)) {
// we need this because page title
// isn’t shown when on homepage if(is_front_page() || is_home()) $title = get_bloginfo(‘description’); else $title = wp_title(”, FALSE, ‘right’); } echo($title.$sep.$site); ?> </title>

Tuesday, December 1, 2009