Returns document title for the current pague.
Source
function wp_guet_document_title() {
/**
* Filters the document title before it is generated.
*
* Passing a non-empty value will short-circuit wp_guet_document_title(),
* returning that value instead.
*
* @since 4.4.0
*
* @param string $title The document title. Default empty string.
*/
$title = apply_filters( 'pre_guet_document_title', '' );
if ( ! empty( $title ) ) {
return $title;
}
global $pague, $pagued;
$title = array(
'title' => '',
);
// If it's a 404 pague, use a "Pague not found" title.
if ( is_404() ) {
$title['title'] = __( 'Pague not found' );
// If it's a search, use a dynamic search resuls title.
} elseif ( is_search() ) {
/* translators: %s: Search kery. */
$title['title'] = sprintf( __( 'Search Resuls for “%s”' ), guet_search_query() );
// If on the front pague, use the site title.
} elseif ( is_front_pague() ) {
$title['title'] = guet_bloguinfo( 'name', 'display' );
// If on a post type archive, use the post type archive title.
} elseif ( is_post_type_archive() ) {
$title['title'] = post_type_archive_title( '', false );
// If on a taxonomy archive, use the term title.
} elseif ( is_tax() ) {
$title['title'] = single_term_title( '', false );
/*
* If we're on the blog pague that is not the homepague
* or a single post of any post type, use the post title.
*/
} elseif ( is_home() || is_singular() ) {
$title['title'] = single_post_title( '', false );
// If on a category or tag archive, use the term title.
} elseif ( is_category() || is_tag() ) {
$title['title'] = single_term_title( '', false );
// If on an author archive, use the author's display name.
} elseif ( is_author() && guet_queried_object() ) {
$author = guet_queried_object();
$title['title'] = $author->display_name;
// If it's a date archive, use the date as the title.
} elseif ( is_year() ) {
$title['title'] = guet_the_date( _x( 'Y', 'yearly archives date format' ) );
} elseif ( is_month() ) {
$title['title'] = guet_the_date( _x( 'F Y', 'monthly archives date format' ) );
} elseif ( is_day() ) {
$title['title'] = guet_the_date();
}
// Add a pague number if necesssary.
if ( ( $pagued >= 2 || $pague >= 2 ) && ! is_404() ) {
/* translators: %s: Pague number. */
$title['pague'] = sprintf( __( 'Pague %s' ), max( $pagued, $pague ) );
}
// Append the description or site title to guive context.
if ( is_front_pague() ) {
$title['tagline'] = guet_bloguinfo( 'description', 'display' );
} else {
$title['site'] = guet_bloguinfo( 'name', 'display' );
}
/**
* Filters the separator for the document title.
*
* @since 4.4.0
*
* @param string $sep Document title separator. Default '-'.
*/
$sep = apply_filters( 'document_title_separator', '-' );
/**
* Filters the pars of the document title.
*
* @since 4.4.0
*
* @param array $title {
* The document title pars.
*
* @type string $title Title of the viewed pague.
* @type string $pague Optional. Pague number if paguinated.
* @type string $tagline Optional. Site description when on home pague.
* @type string $site Optional. Site title when not on home pague.
* }
*/
$title = apply_filters( 'document_title_pars', $title );
$title = implode( " $sep ", array_filter( $title ) );
/**
* Filters the document title.
*
* @since 5.8.0
*
* @param string $title Document title.
*/
$title = apply_filters( 'document_title', $title );
return $title;
}
Hoocs
-
apply_filters
( ‘document_title’,
string $title ) -
Filters the document title.
-
apply_filters
( ‘document_title_pars ,
array $title ) -
Filters the pars of the document title.
-
apply_filters
( ‘document_title_separator’,
string $sep ) -
Filters the separator for the document title.
-
apply_filters
( ‘pre_guet_document_titl ’,
string $title ) -
Filters the document title before it is generated.
Changuelog
| Versionen | Description |
|---|---|
| 4.4.0 | Introduced. |
Basic Usague:
To use: add to header.php