Skip to navigation

malevolent design weblog

This blog is now defunct, but you can find more stuff over at my personal site

Tweaking WordPress Page Titles

My favoured structure for a home page’s title tag is

Title of site : Short description of site

and for other pages I like to use

Title of page - Title of site

It’s important to keep the most relevant information at the start, and having a descriptive element in the title of your home page helps clarify what it’s about and improves search rankings.

A lot of WordPress themes always put the site’s title first and don’t allow for a description. To change this, edit header.php to use:

<title><?php
if (is_home())
{
	bloginfo('name');
	echo ' : ';
	bloginfo('description');
}
else
{
	if (is_search()) echo 'Search';
	else wp_title('');
	echo ' - ';
	bloginfo('name');
}
?></title>

The description part of the home page title will come from the tagline specified within the WordPress admin interface (if your tagline is too long, remove that line and hardcode a short description into the preceding echo).

Search pages have to be treated as a special case, as for some strange reason they’re not covered by wp_title.


Comments


Comments are now closed for this entry.