Codex

Template Tags/wp title

Contents

Description

Displays or returns the title of the page. A separator string can be defined, and beginning with Version 2.5, that separator can be designated to print before or after the title of the page.

This tag can be used anywhere within a template as long as it's outside The Loop on the main page, though is typically used in the <title> element for the head of a page.

The title text depends on the query:

Single post or a Page
the title of the post (or Page)
Date-based archive 
the date (e.g., "2006", "2006 - January")
Category 
the name of the category
Author page 
the public name of the user

Usage

 <?php wp_title('sep', echo, 'seplocation'); ?> 

Examples

Default Usage

Displays the blog name (using bloginfo()) and the post title using defaults when accessing a single post page. If the blog name is "My WordPress Blog", and the title of the post is "Hello world!", then the example below will show the title as My WordPress Blog » Hello world!

 <title><?php bloginfo('name'); ?> <?php wp_title(); ?></title>

This example would the same do the same thing:

 <title><?php bloginfo('name'); ?> <?php wp_title('',true,''); ?></title>

Using Separator

Displays blog name (using bloginfo()) along with post title in the document's title tag, using "--" as the separator. This results in (when on a single post page) My WordPress Blog--Hello world!.

 <title><?php bloginfo('name'); ?> <?php wp_title('--'); ?></title>

This example would do the same thing:

 <title><?php bloginfo('name'); ?> <?php wp_title('--',true,''); ?></title>

Separator with Blog Name and Title Reversed

For Wordpress 2.5 and newer

<title>
 <?php wp_title('--',true,'right'); ?>
 <?php bloginfo('name'); ?>
 </title>

For previous versions

This lets you reverse page title and blog name in the title tag from example above (Hello world!--My WordPress Blog) by removing the separator (using wp_title(' '), then tests if there is a post title (using if(wp_title(' ', false))), and displays the separator between it and bloginfo() if it does.

<title>
 <?php wp_title(' '); ?>
 <?php if(wp_title(' ', false)) { echo '--'; } ?> 
 <?php bloginfo('name'); ?>
 </title>

Parameters

sep 
(string) Text to display before or after of the post title (i.e. the separator). By default (if sep is blank) then the &raquo; (») symbol will be placed before or after (specified by the seplocation) the post title.
echo 
(boolean) Echo the title (True) or return the title for use as a PHP string (False). Valid values:
  • 1 (True) - default
  • 0: (False)
seplocation 
(string) Introduced with Version 2.5, this parameter defines the location of where the sep string prints in relation to the title of the post. For all values except 'right', the sep value is placed in front of (to the left of) the post title. If the value of seplocation is 'right' then the sep string will be appended after the post title.

Related

wp_title, get_posts, query_posts, the_search_query

See also index of Function Reference and index of Template Tags.