You can dynamically set the title tag with PHP code using the WordPress pre_get_document_title
or document_title_parts
filters if you're using Genesis SEO features:
add_filter( 'pre_get_document_title', 'custom_quick_title' );
function custom_quick_title() {
return 'My custom title';
}
The document_title_parts
filter gives you more fine-grained control if you just wanted to override the title or tagline, for example:
add_filter( 'document_title_parts', 'custom_single_title' );
function custom_single_title( $parts ) {
$parts['title'] = 'My custom title';
$parts['tagline'] = 'My site description';
return $parts;
}
These features are part of WordPress itself, and are documented here:
- https://developer.wordpress.org/reference/hooks/pre_get_document_title/
- https://developer.wordpress.org/reference/hooks/document_title_parts/
If the site uses an SEO plugin such as Yoast SEO, you'd need to use that plugin's filters instead. For example, with Yoast:
add_filter( 'wpseo_title', 'custom_yoast_title' );
function custom_yoast_title() {
return 'My custom title';
}
Yoast filters are documented here: https://yoast.com/wordpress/plugins/seo/api/