document_title_separator
Allows you to change the separator in the page title (output in the document head).
The page title in WordPress is output by wp_get_document_title().
Example title and separator:
<!doctype html> <head> ... <title>Hello world! - My Awesome Site</title>
Usage
add_filter( 'document_title_separator', 'wp_kama_document_title_separator_filter' );
/**
* Function for `document_title_separator` filter-hook.
*
* @param string $sep Document title separator.
*
* @return string
*/
function wp_kama_document_title_separator_filter( $sep ){
// filter...
return $sep;
}
- $sep(string)
- Document title separator.
Default: '-'
Examples
#1 Change the separator between parts of the page title
By default, the separator is a dash -. Replace it with ::.
add_filter( 'document_title_separator', 'change_document_title_separator' );
function change_document_title_separator( $sep ){
return ' :: ';
}
Since PHP 7.4, this can be written more concisely using arrow functions:
add_filter( 'document_title_separator', fn() => '::' );
Changelog
| Since 4.4.0 | Introduced. |
Where the hook is called
wp-includes/general-template.php 1476
$sep = apply_filters( 'document_title_separator', '-' );