№ 24. Optimal title in WordPress

The <title> tag

Before we begin, lets set the basis of our discussion: the title of a WordPress page, just like the title of any webpage, isn’t the post-title you write in the editor, but a HTML tag,<title> . Its function is to tell to whom may be concerned (i.e. to browsers or spiders) what is the title of a webpage. The tag’s natural place in the order of cyberbeing is within the <head> tag.

The title tag in WordPress
In plain and static HTML, one has complete control over the document’s title; but WordPress serves pages dynamically, which means your blog basically has a single <head> tag for all the posts and pages you wrote. Of course, this doesn’t mean that everything you write will be named the same for browsers and search engines; the variation is produced by the means of one or more PHP calls that try to be more specific. Let’s take a closer look:

The title tag in the Default theme

wp

wp

OK, I know, you don’t use the Default theme. But, while not using it, it is still very important for your regular blogging activity. As its name suggest, this is the theme that will automatically be served by WordPress if something goes wrong with your regular template (for instance you delete it by mistake). It is also important because it has and may serve all the template files your regular theme has not (e.g. the comments-popup file). Finally, it is very important because many theme designers find in its code their first inspiration.
If you take a second to look into the header file of the Default theme, you’ll see these lines of code:

<title><?php bloginfo(‘name’); ?> <?php if ( is_single() ) { ?> &raquo; Blog Archive <?php } ?> <?php wp_title(); ?></title>

In human language, this means the title of a single page will look something like “Your blog name » Blog archive Your post name”. Would you like your potential visitors to see this kind of title in the SERP? I bet you wouldn’t; and the visitors would remain potential.

The solutions

Actually there are several solutions for this issue.

  • The traditional one is to install the Optimal title plugin by Aaron Schaefer.
  • The easiest solution is to install the beautiful All in one SEO pack plugin.
  • The safest solution: while using All in one SEO pack, you could though optimize the code in the header file.

Why would you bother? Well, just in case you forget to reactivate your plugins after having upgrade WordPress. Or in case you use a plugin that negatively interacts with All in one SEO pack. Finally, because it’s safe and elegant.

The code

The code I use in the themes I design is

<title>
        <?php if ( is_home() ) { ?><?php bloginfo(‘name’); ?> | <?php bloginfo(‘description’); ?><?php } ?>
        <?php if ( is_search() ) { ?><?php bloginfo(‘name’); ?> | <?php echo ‘Search Results for "’; the_search_query(); echo ‘"’; ?> <?php } ?>
        <?php if ( is_single() ) { ?><?php wp_title(); ?> | <?php bloginfo(‘name’); ?><?php } ?>
        <?php if ( is_page() ) { ?><?php wp_title(); ?> | <?php bloginfo(‘name’); ?><?php } ?>
        <?php if ( is_category() ) { ?><?php bloginfo(‘name’); ?> | <?php single_cat_title(); ?><?php } ?>
        <?php if ( is_month() ) { ?><?php bloginfo(‘name’); ?> | <?php the_time(‘F’); ?><?php } ?>
        <?php if ( is_tag() ) { ?><?php bloginfo(‘name’); ?> | <?php  single_tag_title("", true); } ?>
</title>

As you can see, it fits all types of pages generated by WordPress. The output will be more intuitive and definetly more apealing for the potential users.

If you don’t like the code I use, take a look at the classics (Daily Blog Tips and Performancing).

Quick Tip

So, if you decided to change the title tag of your regular theme, why would’t you also change the Default’s theme? Just in case.

Tags: , ,

Published on the 2nd of December, 2008, in WordPress · Print

Leave a Comment on “Optimal title in WordPress”

Some Pings and Trackbacks Are Welcome

  1. Dynamic headings for the blog title | The Theme Museum

Leave a Reply

Recent comments

Colophon

This website was made by Delicia, who is deeply in love with WordPress. It is built on a 30x20px module, with Georgia and Helvetica/Arial. The design is the result of many years she spent reading Wittgenstein.