显示或者返回页面的标题。默认返回一个字符串,自Version 2.5开始支持,这个字符串可以用来指定<head>标签中的标题。
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:
<?php wp_title( $sep, $echo, $seplocation ); ?>
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>
If you don't want it to automatically display the » before the page title, just call the function as below:
<title><?php bloginfo('name'); ?> <?php wp_title("",true); ?></title>
If you are using a custom homepage with custom loops and stuff, you will have an empty wp_title. Here goes a neat hack to add the description/tegline at the wp_title place on homepage:
<title><?php bloginfo('name'); ?> | <?php is_home() ? bloginfo('description') : wp_title(''); ?></title>
Displays blog name (using bloginfo()) along with post title in the document's title tag, using (pipe) "|" as the separator. This results in (when on a single post page) My WordPress Site | 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>
Most common are so called pipes ('|') however there are few other that could be used.
Hyphens
<title><?php bloginfo('name'); ?><?php wp_title('-'); ?></title>
Commas
<title><?php bloginfo('name'); ?><?php wp_title(','); ?></title>
Spaces
<title><?php bloginfo('name'); ?><?php wp_title(' '); ?></title>
When using meta titles site owners need to send a clear message to their users as well as Search Engines. Here are two examples of what websites should avoid.
Double Hyphens
<title><?php bloginfo('name'); ?><?php wp_title('--'); ?></title>
Underscores
<title><?php bloginfo('name'); ?><?php wp_title('_'); ?></title>
Underscores will confuse both users and search engines because the title becomes one word instead of several separated words.
Example when using underscores:
My_WordPress_Site instead of My WordPress Site.
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>