Search Engine Optimization of the Wordpress Title-tag
The default Wordpress setup is not optimized for search engines. To improve the ranking in search engines the first thing that needs to be done is to improve the page title. The default Wordpress title is <blog-title> - <post-title>. From a human perspective that ordering makes sense, but it could be better with regards to the search engines.
When you search for “Linux” the search engine first ensures that the words are used on the page. To figure how relevant the phrase is to the page it counts how many times the phrase is used, as well as where the it occurs and what kind of tags that contain the phrase. In practical terms this means that pages with the search phrase near the top and inside tags that imply importance, e.g. <h1>, <h2> and <em>, will rank higher than those that only have the search phrase inside an ordinary <p> tag at the bottom. Another important tag, probably the most important tag in regards to search engines, is the <title> tag. This tag set the page’s title and it is at the very top of the document. It is therefore important that this tag contains the phrase(s) you want associated with your post, and to increase this phrase’s relevance it should be the first words in the title. This is a very simplistic view of the ranking process, but for our purposes today it works. Other aspects of search engine optimization will be covered as I improve this blog one step at a time.
The first step to improve the Wordpress title tags is to change the order of the blog-title and the post-title, since it is the post-title you (usually) want people to find your posts through. Unfortunately there is no simple way to achieve this in Wordpress, so a little bit of code fiddling is needed. The title is set in your current template’s Header file. To edit this file you have to go to Wordpress admin > Presentation > Theme Editor and you should see the Header file listed as one of the files you can edit.
Once there the bit containing <title>...</title> has to be changed to:
1 2 3 4 5 | <title><?php $t = trim(wp_title('', false)); if(!empty($t)) { echo $t.' | '; } bloginfo('name') ?></title> |
The PHP code is a bit compressed, and it contains two Wordpress specific functions, so it might be a bit hard to understand. What the code does is print our blog-title with a given postfix, here |, if the current page has a post-title, and after that it prints the blog-title.
The wp_title(...) function called on line number 2 returns the current blog posts title with ''(i.e nothing) as the prefix. The false parameter tells the function to return the title, if it is omitted the title is printed directly instead. When the post-title is preceded by the blog-title the prefix is usually used to differentiate between the blog and post name, but since we’re placing the post-title in front of the blog-title we need to use a postfix instead of a prefix. Since there is no way to tell Wordpress that we want a postfix we have to create it ourselves, this is the reason that we cannot print the post-title directly to the screen, but have to store it in our $t variable instead.
Line number 3 prints the post-title and the postfix we desire, in this case a |. We also ensure that it is only printed when we actually have post-title to print, so we avoid the postfix when we’re on the home page. The bloginfo(...) function on line number 4 prints out the blog’s name. The last line simply ends the PHP part, and closes the title-tags since we’re done now.
Once that little bit of code is implemented we get page titles as the ones currently on this page, which are suitable for indexing by a search engine. Now that the search engines read the title as we want it to, we need to ensure that we actually have our target phrases inside the title. Unfortunately there is no magic code snippet that can to that, so we are stuck with formulating a fancy title that contain the words we want as we write our posts.
I’ve seen some people using titles that only contain a list of important phrases without forming a real sentence or meaning only to increase their relevance in search engines. I feel that is taking it a bit too far. If you have that many important things you want to cover it might be better to spread it across multiple posts with each important phrase as the post’s focus. That way the subjects will get more attention, which it should deserve, and the title will still sound good to the humans that read the blog.
Ulmanas Said,
November 6, 2008 @ 03:13
It has long been looking for this information, Thank you for your work.
Michael Plikk Said,
November 8, 2008 @ 14:08
Glad you found the information useful!