wp_get_document_title()
has some interesting filters - pre_get_document_title
and document_title_parts
.
/**
* Filter the parts of the document title.
*
* @since 4.4.0
*
* @param array $title {
* The document title parts.
*
* @type string $title Title of the viewed page.
* @type string $page Optional. Page number if paginated.
* @type string $tagline Optional. Site description when on home page.
* @type string $site Optional. Site title when not on home page.
* }
*/
add_filter( 'document_title_parts', function ( $title ) {
if ( is_home() || is_front_page() )
unset($title['tagline']);
return $title;
}, 10, 1 );
Looking back on this; the pre_get_document_title
filter is pretty interesting. Essentially before it processes the title it'll run this filter. If the result isn't empty (which was not expected) then the process is short-circuited.
$title = apply_filters( 'pre_get_document_title', '' );
if ( ! empty( $title ) ) {
return $title;
}
That means that if you defined the title, it doesn't have to worry about anything else. The nice thing is that you can make exceptions to the rule. So to answer your original question:
add_filter( 'pre_get_document_title', function( $title ) {
if ( is_home() || is_front_page() ) {
// Return blog title on front page
$title = get_bloginfo( 'name' );
}
return $title;
} );