Забирайте проверки по всем условным тегам
$separator = '|';
// Title prefixes.
if ( is_post_type_archive() ) {
$title[] = _x( 'Archives:', 'post type archive title prefix', 'wpgen' );
} elseif ( is_category() ) {
$title[] = _x( 'Category:', 'category archive title prefix', 'wpgen' );
} elseif ( is_tag() ) {
$title[] = _x( 'Tag:', 'tag archive title prefix', 'wpgen' );
} elseif ( is_author() ) {
$title[] = _x( 'Author:', 'author archive title prefix', 'wpgen' );
} elseif ( is_date() ) {
if ( is_year() ) {
$title[] = _x( 'Year:', 'date archive title prefix', 'wpgen' );
} elseif ( is_month() ) {
$title[] = _x( 'Month:', 'date archive title prefix', 'wpgen' );
} elseif ( is_day() ) {
$title[] = _x( 'Day:', 'date archive title prefix', 'wpgen' );
}
} elseif ( is_tax( 'post_format' ) ) {
if ( is_tax( 'post_format', 'post-format-aside' ) ) {
$title[] = _x( 'Asides', 'post format archive title', 'wpgen' );
} elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
$title[] = _x( 'Galleries', 'post format archive title', 'wpgen' );
} elseif ( is_tax( 'post_format', 'post-format-image' ) ) {
$title[] = _x( 'Images', 'post format archive title', 'wpgen' );
} elseif ( is_tax( 'post_format', 'post-format-video' ) ) {
$title[] = _x( 'Videos', 'post format archive title', 'wpgen' );
} elseif ( is_tax( 'post_format', 'post-format-quote' ) ) {
$title[] = _x( 'Quotes', 'post format archive title', 'wpgen' );
} elseif ( is_tax( 'post_format', 'post-format-link' ) ) {
$title[] = _x( 'Links', 'post format archive title', 'wpgen' );
} elseif ( is_tax( 'post_format', 'post-format-status' ) ) {
$title[] = _x( 'Statuses', 'post format archive title', 'wpgen' );
} elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
$title[] = _x( 'Audio', 'post format archive title', 'wpgen' );
} elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
$title[] = _x( 'Chats', 'post format archive title', 'wpgen' );
}
}
// Main title.
if ( is_single() || is_page() ) {
$title[] = get_the_title();
} elseif ( is_404() ) {
$title[] = __( 'Page not found', 'wpgen' );
} elseif ( is_search() ) {
$title[] = sprintf( __( 'Search Results for “%s”', 'wpgen' ), get_search_query( false ) );
} elseif ( is_post_type_archive() ) {
$title[] = get_queried_object()->label;
} elseif ( is_author() ) {
$title[] = get_queried_object()->display_name ?? '';
} elseif ( is_date() ) {
if ( is_year() ) {
$title[] = get_the_date( 'Y' );
} elseif ( is_month() ) {
$title[] = get_the_date( 'F Y' );
} elseif ( is_day() ) {
$title[] = get_the_date( 'F j, Y' );
}
} elseif ( is_archive() ) {
$title[] = get_queried_object()->name;
}
// Add site info in the title.
if ( ! isset( $title ) ) {
$title[] = get_bloginfo( 'name' );
$title[] = $separator;
$title[] = get_bloginfo( 'description' );
} else {
if ( is_paged() ) {
$title[] = $separator;
$title[] = __( 'Page', 'wpgen' ) . ' ' . $paged;
}
$title[] = $separator;
$title[] = get_bloginfo( 'name' );
}
$title = implode( ' ', $title );