What code do you use to generate the text to go into the HTML title tag?

The question title says it all. Myself I just stick with the default code from one of the packaged templates that comes with WordPress out of the box:

<title><?php
    /*
     * Print the <title> tag based on what is being viewed.
     */
    global $page, $paged;

    wp_title( '|', true, 'right' );

    // Add the blog name.
    bloginfo( 'name' );

    // Add the blog description for the home/front page.
    $site_description = get_bloginfo( 'description', 'display' );
    if ( $site_description && ( is_home() || is_front_page() ) )
        echo " | $site_description";

    // Add a page number if necessary:
    if ( $paged >= 2 || $page >= 2 )
        echo ' | ' . sprintf( __( 'Page %s', 'twentyeleven' ), max( $paged, $page ) );

    ?></title>

Do any of you use different code for this?

Related posts

Leave a Reply

2 comments

  1. Mine is:

      function getDocumentTitle($separator = " &laquo; "){
    
        $title = get_bloginfo('name');
        $desc = get_bloginfo('description');
    
        if(is_front_page() && is_home() && !empty($desc)){
          $title .= $separator.$desc;
    
        }elseif(is_home() || is_singular()){
          $id = $GLOBALS['wp_query']->get_queried_object_id();
          if($meta = get_post_meta($id, 'title', true)) $title .= $separator.$meta;
          $title .= (empty($meta) && is_front_page() && !empty($desc)) ? $separator.$desc : $separator.get_post_field('post_title', $id);
    
        }elseif(is_archive()){    
          if(is_category() || is_tag() || is_tax()){
            $term = $GLOBALS['wp_query']->get_queried_object();
            $title .= $separator.$term->name;
    
          }elseif(is_author()){
            $title .= $separator.get_the_author_meta('display_name', get_query_var('author'));
    
          }elseif(is_date()){
            if(is_day())
              $title .= $separator.sprintf(_a('Archive for %s'), get_the_time(apply_filters('doc_title_archive_day_format', 'F jS, Y')));
            elseif(get_query_var('w'))
              $title .= $separator.$separator.sprintf(_a('Archive for week %1$s of %2$s'), get_the_time('W'), get_the_time('Y'));
    
            elseif(is_month())
              $title .= $separator.sprintf(_a('Archive for %s'), single_month_title(' ', false));
            elseif(is_year())
              $title .= $separator.sprintf(_a('Archive for year %s'), get_the_time('Y'));
    
          }else{
            $title .= $separator.post_type_archive_title('', false);
    
          }
    
        }elseif(is_search()){
          $title .= $separator.sprintf(_a('Search results for %s'), '&quot;'.get_search_query().'&quot;');
    
        }elseif(is_404()){
          $title .= $separator._a('404 Not Found');
    
        }
    
        // paged?
        if((($page = $GLOBALS['wp_query']->get('paged')) || ($page = $GLOBALS['wp_query']->get('page'))) && $page > 1 && !is_404())
          $title .= $separator.sprintf(_a('Page %s'), $page);
    
        // comment page?
        if(get_query_var('cpage'))
          $title .= $separator.sprintf(_a('Comment Page %s'), get_query_var('cpage'));
    
        // apply the wp_title filters so we're compatible with plugins
        return apply_filters('wp_title', $title, $separator, '');
      }