How does one check if the title, generated by wp_title()
has empty space in front of it? I have found how to trim it with trim()
<?php echo trim(wp_title('', false)); ?>
But, like with setting a wp_title()
for home page, I’d like to put this in the functions.php
file, so that it’s not in my header. So far I have
add_filter( 'wp_title', 'trim_wp_title' );
function trim_wp_title( $title ) {
if( /* check if $title contains empty space */ ) {
$title = echo trim(wp_title('', false));
}
return $title;
}
You don’t really need to do the check at all, your function can be simplified down to:
trim
will just leave the string as it is if there’s nothing to trim off of it.Do you want something like this?