Wednesday, April 30, 2008

Tip: Reorder your Title Tag

WordPress, by default, creates tags that look like this: <title>Yoursite » Your Post Title. Many people want to use Your Post Title » Yoursite instead, to give more importance to the mutable part of the . There are plugins to do this, but I’d like to show you how a simple change in your theme can accomplish this task. <ins>Caveat: this only works in WordPress 2.5 and above.</ins></p> <ol><li>Open your <code>header.php</code> theme file (if you don’t have one, open <code>index.php</code> or whatever one has your <title> tag)</li><li>Look for: <br /><code><title><?php bloginfo('name'); ?> <?php if ( is_single() ) { ?> » Blog Archive <?php } ?> <?php wp_title(); ?>
(or something similar)

  • Replace it with:
    <?php wp_title('»', true, 'right'); ?> <?php bloginfo('name'); ?>
  • The first wp_title() argument is the separator character. I like » (which looks like: »). The second argument is whether to echo (print to the browser) the title, or to return it. We want to print it, so we put true. The final argument is where the separator should go… on the left or on the right. We want right, so we put "right". Simple enough!

    No comments: