Last updated on December 15, 2009. Tags: HTML title, title tag
WordPress was specifically created as a blogging platform wherein the articles or posts is expected to bring traffic from the search engines instead of the pages. In WordPress or blogging in general, the term "page" refers to those supplementary dynamic pages that are found in a typical website such as the home page, the "about us" page and the "contact" page.
Most WordPress themes are correctly optimized for search engines by including the post title in the HTML title because post titles usually contain the relevant keywords for that post, not to mention that some bloggers and web masters are good in writing search engine friendly (and coherent) post titles. Moreoever, you can further optimized your WordPress blog by rearranging the post title and the blog title in the HTML title tag.
However, the same strategy is not feasible for WordPress pages. Pages are usually given short titles, about one or two words in length. Similar to posts, the page title of a page also becomes the text link that leads to that page in the navigation menu.
Imagine this scenario, suppose you have an electronic gadgets review blog. To make your home page more optimized for search engine, you changed its title from "Home" to something like "Product reviews of mobile phones, digital cameras, MP3 players and other electronic gadgets". WordPress will include this phrase in the HTML title and therefore, the search engines will associate the words in this phrase to your home page.
You'll think it's a better title than "Home". Anyway, your website is not about homes.
But wait! This phrase looks too wordy for your page menu, especially if the page menu of your WordPress theme is arranged horizontally either above or below the banner; it does not look good. Note that whatever title you give to your pages also becomes the hyperlink title leading to it in the navigation menu.
Even if your page menu has the same formatting as the post list (Recent Entries), people who arrived to your site from one of your blog posts might decide to look for home page; they will immediately look for words like "Home" or "Main" in the navigation menu. They will find your site very confusing if they cannot find a link that is suppose to lead them to home page simply because it was not properly labeled.
Aside from home page, another page that you might want to have a search engine optimized HTML title is the "Services" page. This page usually appear to those websites that operates both as a blog and as a business website.
A better HTML title is one that mention the type of services provided. Something like "Our services include Website Design, WordPress Customization and SEO". However, similar to the case of the home page, this is also too wordy for the navigation menu.
The solution: Use separate PHP if function to provide each page with its own HTML title as shown in the sample code below.
<title>
<?php
if (is_single() ) { single_post_title(); echo' - '; bloginfo('name'); }
elseif (is_home() ) { echo'This HTML title describes this entire website'; }
elseif (is_page(2) ) { echo'In this HTML title, provide a short one-sentence description about your company'; }
elseif (is_page(3) ) { echo'Our services include Service 1, Service 2 and Service 3'; }
elseif (is_page() ) { single_post_title(); echo' - '; bloginfo('name'); }
elseif (is_single() ) { single_post_title(); echo' - '; bloginfo('name'); }
elseif ( is_category() ) { single_cat_title(); echo' - '; bloginfo('name'); }
elseif ( is_tag() ) { single_cat_title(); echo' - '; bloginfo(‘name’); }
elseif ( is_search() ) { echo'Search results for '; the_search_query(''); echo' - '; bloginfo('name'); }
elseif ( is_archive() ) { the_time('F Y'); echo' - '; bloginfo('name'); }
else { bloginfo('name'); }
?>
</title>
To use the PHP code above, follow these instructions
In the code above, we assume that the post ID "About Us" page is 2 (fifth line) and that of "Services" page is 3 (sixth line). The rest of the pages (the seventh line) not specified will have HTML title in the form of <page title> - <blog title / website name>.
You may simply replace 2 and 3 with whatever post IDs were assigned to your home page, "About Us" page and "Services" page, or whatever post ID were assigned to the pages that you would like to have their own HTML titles.
Except for the WordPress pages, the code above works in the same way as the one we have in an earlier article about SEO of WordPress title tags.
If you have more than three pages and would like to assign unique HTML title for each of them, you can duplicate the fifth or the sixth line as many times as you need and replace it with the appropriate post ID.
The fourth line [elseif (is_home()...] determines the HTML title of the home page. However, it will work IF AND ONLY IF the home page is the list of most recent posts (the default WordPress configuration). If your home page is a static page (as you can configure in your WordPress setting), get its post ID and make another elseif line similar to the fifth and sixth line.
Then, you can choose whether or not to delete the third line is_home() since you won't be needing it as long as you have a static page as your home page.
Suppose the post ID of your static home page is 1, and you choose to delete the is_home() line, the upper part of your code should like this.
<title>
<?php
if (is_single() ) { single_post_title(); echo' - '; bloginfo('name'); }
elseif (is_page(1) ) { echo'This HTML title describes this entire website'; }
elseif (is_page(2) ) { echo'In this HTML title, provide a short one-sentence description about your company'; }
elseif (is_page(3) ) { echo'Our services include Service 1, Service 2 and Service 3'; }
elseif (is_page() ) { single_post_title(); echo' - '; bloginfo('name'); }
elseif (is_single() ) { single_post_title(); echo' - '; bloginfo('name'); }
.
.
.
While posts can have the luxury of having long titles that contain relevant keywords, the pages do not have the same privelage. Web users are accustomed to shorter page names like "home" or "main", "about us" and "contact us", and providing these pages with longer titles may confuse human visitors and does not look good in some WordPress theme. By using the post ID of these pages, we can retain the short and more familiar page titles while providing search engine friendly HTML title.
Posted by Greten on February 15, 2009 under Hypertext Mark-up Language (HTML), Search Engine Optimization (SEO), WordPress tweaks
Please double check your comment before clicking the "Post" button. Once you clicked it, there will be no way for you to edit your comment.
* Required. Your email will never be displayed in public.