One of today’s post by Darren Rowse of ProBlogger prompted me to figure out how to change the code on my blog so that my titles were more Search Engine friendly.
I have never liked the way wordpress displays the title by default. I wanted my blog to display only the title of the post in the title bar when you were on the post page. So I decided to change that.
NOTE: If you don’t know what the title tag is, go back and look at this post on my other blog.
To change the default title tag in wordpress you need to edit the header.php for the theme that you are using.
The line of code you want to change will look something like this:
<title>< ?php bloginfo('name'); ?> < ?php wp_title(); ?> </title>
Replace that code above with the code you want to use. Here is the code I am using on this blog (and will be soon using on all my blogs):
< ?php if(is_home())
{ echo '<title>'; echo bloginfo('name');
echo '< /title> '; }
else
{ echo '<title>'; wp_title(' '); echo '</title>'; } ?>
The code above displays the name of my blog as the title if you are on the home page. Otherwise, it only displays the post name if you are on a post page, the name of the archive page if you are on an archive page, or the category name if you are on category page.
It’s kind of funny how long it took it me to figure this out. I made it much more complicated than it needed to be. At one point the code looked like this:
< ?php if(is_home()) { echo '<title>';echo bloginfo('name'); echo '< /title> '; } else if ( is_category() ) {echo '<title>'; wp_title(); echo '</title>';} else if ( is_archive() ) { echo '<title>'; wp_title(); echo '</title>';} else { echo '<title>'; the_title(); echo '</title>'; } ?>
While it did the job, it was overkill.
Fortunately, I found the WordPress wiki and was able to quickly find the code changes I needed to make from there.
Another option for changing the way your title displays in WordPress is to use the Optimal Title WordPress Plug-in. But I prefer making the code change above.