The Perfect Title Tag

In Version 2.5 Template Tag wp_title got an update, therefore Plugins became useless for that.

By the way, the code came from the Plugin „Optimal Title“.

The title tag is in the header, therefore in header.php . The following syntax works in all WP-versions, but it’s not a perfect way for WordPress higher than 2.5. I will show you a perfect title tag for WordPress 2.6 and higher.


Since version 2.5 the function wp_title has following parameters, also they are already filled and it’s not really necessary to use parameters.

  • sep – delivering a separator character, separator or text before and after the post
  • display – displaying title; interesting if you don’t want to display the title, instead a variable and use it furthermore
    • 1 (True) – standard
    • 0 (False)
  • seplocation – left (left) or right (right) of the post title should be the character or text. Below are 2 examples how it could look like.
wp_title($sep = '»', $display = true, $seplocation = '')

The above variant for WordPress earlier than version 2.5 could look like this in WordPress Version 2.5*.


Display with different parameters seplocation looks like that. The blog name is „WordPress Book“.

Left

 - WordPress Plugins for better security - WordPress Book

Right

WordPress Plugins for better security - WordPress Book

I like to display the category, since it’s an added value for the reader, especially if they like to bookmark the page. It isn’t relevant for search engines since I limited indexing it by following:

' . "\n"; } else { echo '' . "\n";} ?>


In this combination you can replace !is_paged() ) && ( is_single() with the new tag is_front_page() on your front page. This conditional tag is available since version 2.5.

Further resources


Posted

in

by

Comments

4 responses to “The Perfect Title Tag”

  1. Ryan McCue Avatar

    _e() is not an alias for echo and should not be used as such. It is for translation purposes.

    All of your _e(‘ – ‘); lines should be echo ‘ – ‘;

  2. Michael Avatar

    Yes i know, but we are german and we use those functions in our themes for translation purposes. Sorry for the mistake 😉

  3. jbj Avatar

    Very nice post, lots of usefull information. Thanks for sharing 🙂

  4. Rob Mason Avatar

    The seplocation thing had been bugging me for ages and couldn’t find a suitable solution. Now I have! Huge thanks

    R