Wp_title function in WordPress is used to display articles, pages, categories, and so on the title of a function, but on the index of the first page, the function will not show anything. This function has been used in WordPress's official theme, but this function is always ignored in many custom topics.
A detailed explanation of function meaning
the Wp_title function is used to display the title of the page, as in the article page, the title of the article, and the category name on the category page, but the function will not display anything in the index on the first page.
A bit like the Get_the_title and Single_cat_title () of WordPress () the adaptive use of these two functions (automatic judgment is the page, article or category, archive, label).
function declaration
a little long, I hope you can be patient to read it again, even if only once.
/** * Display or retrieve page title for all areas of blog. * By default, the page title would display the separator before the page title, * So the blog title would be before The page title. This isn't good for * title display, since the blog title shows up most tabs and not what are * important, which is T
He page, the user is looking at. * * There are also SEO benefits to have the blog title after or to the ' right ' * or the page title. However, it is mostly common sense to have the blogger title * to "right" with most browsers supporting. You can achieve this with * using the seplocation parameter and setting the value to ' right '.
This change * was introduced around 2.5.0, in case backwards compatibility the themes is * important. * * @since 1.0.0 * * @param string $sep Optional, default is '» '.
How to separate the various items within the page title. * @param bool $display Optional, default is true.
Whether to display or retrieve title. * @param StThe Ring $seplocation Optional.
Direction to display title, ' right '.
* @return String|null string on retrieve, or null when displaying.
* * Function wp_title ($sep = '» ', $display = true, $seplocation = ') {global $wpdb, $wp _locale;
$m = Get_query_var (' m ');
$year = Get_query_var (' year ');
$monthnum = Get_query_var (' Monthnum ');
$day = Get_query_var (' Day ');
$search = Get_query_var (' s ');
$title = '; $t _sep = '%wp_titile_sep% '; Temporary separator, for accurate flipping, if necessary//if there is a post if (Is_single () | | (Is_home () &&!is_front_page ()) | | (Is_page () &&!is_front_page ())
{$title = Single_post_title (', false ');}
If there ' s a category or tag if (is_category () | | Is_tag ()) {$title = Single_term_title (', false);}
If there ' s a taxonomy if (Is_tax ()) {$term = Get_queried_object ();
$tax = get_taxonomy ($term->taxonomy);
$title = Single_term_title ($tax->labels->name. $t _sep, false);
}//If there ' s an authorif (Is_author ()) {$author = Get_queried_object ();
$title = $author->display_name;
}//If there ' s a post type archive If (is_post_type_archive ()) $title = Post_type_archive_title (', false ');
If there ' s a month if (is_archive () &&!empty ($m)) {$my _year = substr ($m, 0, 4);
$my _month = $wp _locale->get_month (substr ($m, 4, 2));
$my _day = intval (substr ($m, 6, 2)); $title = $my _year. ($my _month $t _sep. $my _month: ").
($my _day $t _sep. $my _day: ");
//If there ' s a year if (Is_archive () &&!empty ($year)) {$title = $year; if (!empty ($monthnum)) $title. = $t _sep.
$WP _locale->get_month ($monthnum); if (!empty ($day)) $title. = $t _sep.
Zeroise ($day, 2); //If it's a search if (Is_search ()) {/* Translators:1: Separator, 2:search phrase/$title = sprintf (' Searc
H Results%1 $ s%2$s '), $t _sep, Strip_tags ($search));
//If it ' s a 404 page if (is_404 ()) {$title = __ (' Page not Found ');}
$prefix = '; If (!empty ($title)) $prefix = "$sep"; Determines position of the separator and direction of the breadcrumb if (' right ' = $seplocation) {//Sep on right,
So reverse the order $title _array = explode ($t _sep, $title);
$title _array = array_reverse ($title _array); $title = Implode ("$sep", $title _array).
$prefix;
else {$title _array = explode ($t _sep, $title); $title = $prefix.
Implode ("$sep", $title _array);}
$title = apply_filters (' Wp_title ', $title, $sep, $seplocation);
Send it out if ($display) echo $title;
else return $title;
}
Usage
<?php Wp_title ($sep, $echo, $seplocation);?>
Parameter detailed
- $SEP: separator;
- $echo: whether to display;
- $seplocation: The location of the separator (left or right, only accept ' yes ', if right is not automatically judged to be left)
Summarize
There are many functions of the same function in WordPress, are from the grassroots to the advanced continuous encapsulation finally reached the use layer, of course, if we need some flexible use, we can directly use the middle layer of functions, if we are lazy we can directly use the highest level of the function, such as this function wp_ Title, in fact, this function we look at the source code, WP for us for classification, tags, articles, archives, authors, pages and other types of pages are judged, and according to different pages call different title function to achieve the goal.
If you have the time, you can study the following functions in depth, and more flexible for SEO
Single_post_title article page extract title function
The single_term_title tag (tag), Cat (category), date, and Fetch header function are similar to the Single_cat_title () function
Get_queried_object Author page Extracts a function of an object (with an author name in the object)
Post_type_archive_title () and so on to extract the title function
What are you waiting for?
Go Go Go!