Theme support title tag - how to replace the default WP separator (with a filter)?
-
20-04-2021 - |
Question
I'm developing a theme for Themeforest and one of their requirements is about the tag. Themeforest states their requirement as follows:
The theme must let WordPress add and manage the title. This is done by adding add_theme_support( 'title-tag' );
to functions.php instead of using wp_title()
in the document head.
The current output is on the home page: 'Site title - Site tagline
'. On other pages it is 'Post or page title - Site tagline
'.
The separator is '-'. Can anyone give an example of a filter for this, so that I can change the separator to '|' or a character of my choice?
Many thanks in advance!
Solution
You use the document_title_separator filter.
So in your case:
<?php
function theme_prefix_filter_document_title_separator() {
return '|';
}
add_filter( 'document_title_separator', 'theme_prefix_filter_document_title_separator' );
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange