Possibility-1:
If your theme has:
add_theme_support( 'title-tag' );
somewhere in your functions.php
file, and
wp_head()
function call in header.php
file
then using document_title_separator
filter will work as @Paul's answer suggested.
If the filter doesn't work even after meeting those conditions above, then perhaps a plugin is overriding it. Try increasing the priority of the filter so that it runs last, like so:
function wpse262196_document_title_separator( $sep ) {
return '|';
}
add_filter( 'document_title_separator', 'wpse262196_document_title_separator', PHP_INT_MAX );
or if the document_title_separator
filter already exists in your theme's functions.php
file, then change it there.
Possibility-2:
May be your theme doesn't include add_theme_support( 'title-tag' );
and instead uses the old <title><?php wp_title(); ?></title>
in header.php
file.
In this case, you may change it like: <title><?php wp_title( '|' ); ?></title>
to change the separator.
Note: it's strongly advised to change it back to add_theme_support( 'title-tag' );
, as wp_title()
is likely to be deprecated.
Also, if it doesn't work, then may be your a plugin is replacing it using wp_title
filter. In that case, use the filter below in your themes functions.php
file to change the behaviour:
function wpse262196_wp_title( $title, $sep, $seplocation ) {
return str_replace( " $sep ", " | ", $title );
}
add_filter( 'wp_title', 'wpse262196_wp_title', PHP_INT_MAX );
or if the wp_title
filter already exists in your theme's functions.php
file, then change it there.
Hopefully one the solutions will work for you.