Enhancing the WordPress Title Element
I have written about page titles in WordPress before, but when I made my new theme I found another alternative. I feel this method provides slightly better results across a wider range of installations.
In the header.php file you need to look for the title element. It looks like this: <title></title>
, but this is the element only, shown without its content. What you’ll probably see is this code (on one line):
<title> <?php bloginfo('name'); ?> <?php if ( is_single() ) { ?> » Blog Archive <?php } ?> <?php wp_title(); ?> </title> <!--This would normally be shown on one line but doesn’t have to be-->
With my improvements more information will be shown, including search terms on the search results page and a title error for the error page (404.php).
<title> <?php bloginfo('name'); ?> » <?php bloginfo('description'); ?> <?php if(is_home()) { ?> » Home Page <?php } ?> <?php if(is_single()) { ?> <?php } ?> <?php wp_title(); ?> <?php if(is_404()) { ?> » 404 Error! Page Not Found <?php } ?> <?php if(is_search()) { ?> » Search Results for: <?php echo wp_specialchars($s, 1); ?> <?php } ?> </title> <!--This would normally be shown on one line but doesn’t have to be-->
To use this, copy the code shown and paste it into the header.php file where your title element currently lives. That’s it.
Update:
Due to the great feedback I got on this post I updated the title script and recommend this one. In mine, unless you edit a core function file, replace instances of “-
” with “»
” in the scripting shown.
Adam H responds:
Posted: February 5th, 2007 at 6:58 pm →
I think the SEO guys won’t like this one too much. The dangers of a really long page title is search engines only show a set amount of characters and cut the rest with an ellipsis. For example your search results for this blog don’t have relevant titles that would draw the user to click when compared to other results for a given search string.
A good example of a well branded title tag would be that of Wikipedia. Check out the search results for SEO. It would be easy to rearrange your example to the form: H1 title - Site Brand, Site tag-line. That way the unessential tag-line is the first to go.
David Zemens responds:
Posted: February 5th, 2007 at 7:36 pm →
Another slick idea, Mike. Thanks much.
Mike Cherim responds:
Posted: February 5th, 2007 at 7:52 pm →
@ Adam: Some of it would depend on the length and relevance of the blog description. I did leave that on line one and it would be easy to remove. The results are clear here though (and this blog has never been really optimized until I did the re-boot, and still it’s not as good as I could make it): Case in point, a search via Google for Accessible Contact Form yields well (or “PHP Contact Form,” “WordPress Contact Form,” even “Contact Form”). I have many of my titles that show up high on Google so there must be something to it. But to optimize further the post title would come first. There is a difference in what Google posts on their search results page versus what Google indexes. But your point is well noted. To optimize further the post/page title should be first.
@ David: Thanks.
Rich Pedley responds:
Posted: February 7th, 2007 at 6:43 am →
Ignoring the fact that I hate long title’s, is this good for accessibility? I’m not so sure it is. Isn’t a page title read out when a user visits a page using JAWS (to pick on screen reader at random).
Short and concise title’s may be better and more friendly.
In case you ask why I don’t like them - just add the page to your bookmarks, most of mine are short and concise, I have very very few that are that long. Editing everyone becomes a pain!
Mike Cherim responds:
Posted: February 7th, 2007 at 10:11 am →
Good point Rich, the description is what kills it. Tell you guys what, here’s a mod:
This will produce “Beast-Blog.com » Enhancing the WordPress Title Element” and that could be turned around a bit to make it “Enhancing the WordPress Title Element » Beast-Blog.com”
This last one hasn’t been tested and may need tweaking.
Mike Cherim responds:
Posted: February 7th, 2007 at 10:22 am →
I changed what I’m using here to this:
Please note that I used a hyphen “-” separator, but this requires a core file edit if it is to be show as such in all instances. The other article has details on how to do that.
Edit: This is actually much better. Thanks for the feedback guys.
Optimizing WordPress for Search Engines » Beast-Blog.com responds:
Posted: April 18th, 2007 at 9:57 am →
[…] What I suggest in most instances is to use this element to house the site name and page title. With WordPress I suggest the title element be used to house the blog/site name and blog/site description on the main page — and that the description be carefully thought out (more so than what I use it for on my blog). I also suggest that the page title on pages other than the main page come first as this produces a better result of a Google search page since only so much information is shown (as suggested by Adam Hewgill in this post comment in response to a prior post on this subject). Here’s what I am offering: […]