Depending on how you are outputting the title, the answer is different. But there are two possibilities.
By Using wp_title();
If your theme is using the wp_title();
function in its header.php
file, you can use the wp_title
filter. However, this function is being deprecated since 4.4.
add_filter( 'wp_title', 'filter_the_title' );
function filter_the_title( $title ) {
$title = str_replace( ' ', ',' , $title);
return $title;
}
By Using add_theme_support( 'title-tag' );
Newer themes add this method to enable the title tag support. If this is your case, you can use the pre_get_document_title
filter to do so.
add_filter( 'pre_get_document_title', 'filter_the_title' );
function filter_the_title( $title ) {
$title = str_replace( ' ', ',' , $title);
return $title;
}