Search engine optimization (SEO) of WordPress theme title tags

Last updated on January 30, 2010. Tags: ,

As stated in this earlier article about using HTML title for SEO, HTML title is a truly powerful code for search engine optimization or SEO. Search engines should be able to easily associate your site with certain key phrases and human visitors should have a quick idea on whether or not your website is the one they are looking for. Therefore, HTML title should tell what your website is all about.

Writing a search engine friendly title is easier (but more time-consuming) if you are manually creating each HTML page of your website. However, if you are using WordPress, determining the HTML title of each WordPress generated dynamic page (WordPress pages, posts, categories, search results, etc) requires that you to manipulate some parts of the PHP code.

The HTML title of WordPress is already optimized for search engine because the post title (title that you type while composing the post or page) is already included in the HTML title. Most WordPress themes work in a way that the HTML title is the title of the blog followed by the page title or the post title; something like Blog Title » Post Title or Blog Title » Category » Post Title.

However, the post title is usually the one that contain relevant keywords about the post and not the blog title. Therefore, we can improve the search engine optimization of HTML title by having the post title come first before the blog title. Note that blog visitors usually enters the site through one of the posts and not through the home page.

Shot code for WordPress title tag SEO

To have page title in this form, follow the following steps:

  1. Open the theme editor in your WordPress administration panel.
  2. Open the header.php
  3. Highlight the <title> and </title> tags and everything between them.
  4. Delete everything that you've highlightned and paste the PHP code below in its place.
<title>
<?php if ( is_front_page()  ) { bloginfo('name'); echo' - '; bloginfo('description'); }
else { wp_title('-', true, 'right'); bloginfo('name'); }
?>
</title>

In the code above, the format of the title will be as follows:

NOTE 1: The argument is_front_page() refers to whatever homepage is assigned regardless if it's a static page or a list of recent posts. If it's a static page, then the home page will still have the <site name> - <site description> format for title tag and not the <page title> - <site name> format of pages.

You can replace the is_front_page() with is_home(). The difference between the two is that the former is being followed regardless of whether your home page is a static page or a list of post while the latter applies only if the home page is a list of recent posts. I'll explain the difference between the two in one of my future posts

NOTE2: In wp_title('-', true, 'right'); , you can replace '-' with whatever character separator you want between post/page/category title and blog name like &raquo;.

NOTE3: Some search engine optimizers advised that it would be more helpful to remove the site title in its entirety and simply have the post title in the title tag. Even though I haven't personally tested the validity of this claim, in case you would like to follow such advice, simply remove the bloginfo('name'); part and replace wp_title('-', true, 'right'); with
wp_title(' ', true, ' ');.

If you will notice, except for the home page, all other pages are generated only by the third line. While you can format wp_title() in several different ways based on the arguments inside the parentheses, the ways you can format the title tags of different types of WordPress pages: static, post, category, etc., are very limited. I will explain the behavior and capabilities of wp_title() in one of my future posts, but for now, we can check a longer alternative code in the next section.

Longer but easier to format

Instead of the code presented earlier, you can also replace the title tag of WordPress with the longer code below. Just follow steps 1 to 4 as discussed in this page but this time, use the code below.

<title>
<?php if ( is_front_page()  ) { bloginfo('name'); echo' - '; bloginfo('description'); }
elseif ( is_search() ) { echo'Search Results'; }
elseif ( is_tag() ) { single_cat_title(); echo' - '; bloginfo('name'); }
elseif ( is_category() ) { single_cat_title(); echo' - '; bloginfo('name'); }
elseif ( is_archive() ) { the_time('F Y'); echo' - '; bloginfo('name'); }
elseif ( is_attachment() ) { wp_title(' '); echo' - '; bloginfo('name'); }
elseif ( is_single() ) { wp_title(' '); echo' - '; bloginfo('name'); }
elseif ( is_page() ) { wp_title(' '); echo' - '; bloginfo('name'); }
elseif ( is_404() ) {  echo'Ooopps! Not here!'; echo' - '; bloginfo('name'); }
else { bloginfo('name'); }
?>
</title>

In the code above, the format of the title will be as follows:

In this code, though it's longer, you can change the format of different kinds of WordPress pages in several different ways without being restricted to the capabilities of wp_title(). For example, you can control the format of archive page titles using the_time() WordPress tag.

Optimizing the static pages further

The above codes have one flaw. While post titles usually contain the relevant keywords for that post, page titles are usually shorter and generic; this results to a shorter and more general HTML title such as Home - Blog Title in the home page.

This is not a big problem for most blogs because as I stated earlier, visitors usually come through the posts rather than the home page. However, to use HTML title tags for its full SEO potential, you would want to at least, have a home page with HTML title that tells what your website is all about. Moreover, if your website functions both as a blog and as a business website, you would want to have your other pages, like the "About Us" and "Services" on top of search results.

You might be tempted to change the titles of your pages from one or two word (e.g., Home, About Us) into longer phrases with a lot of keywords. However, that would be messy in your navigation menu especially if your page menu is not on the sidebar but arranged horizontally on top of the page or under the blog name where the space is limited.

One solution I would suggest to be able to create a search engine optimized HTML title for pages is discussed in this article: Search engine optimization (SEO) of WordPress page title tag

Title tag is one of the most important parameters that the search engines use to associate certain keywords with your website. Controlling what words appear in the title tag is very important in search engine optimization. Even if you are using PHP platform, being able to control this parameter will definitely give boost to your SEO effort.

<?php
if (is_single() ) { single_post_title(); echo' - '; bloginfo('name');
elseif (is_page() ) { 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'); }
?>

Posted by Greten on January 12, 2009 under Hypertext Mark-up Language (HTML), Search Engine Optimization (SEO), WordPress tweaks

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • StumbleUpon
  • Technorati

Related Posts

You might also be interested (randomly generated):

Read Comments

  1. Posted by mysuperwoofer on 07.18.10 4:09 am

    there are many search engine optimization on wordpress, but I found this article is better, I like it very much. Give many thanks

Post Comments

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.