Yoast for WordPress: No space in page titles

Author: hung
Date: 06/10/21 10:16:59

Whenever I use the SEO plugin Yoast, I usually end up with the problem that the name of the WordPress site is added to the end of each page title, without a space before it.

I’m just getting the new site for Performance Verbier ready for launch, and the home page title was displaying as:

Verbier Ski School : Private Ski LessonsPerformance Verbier

However the snippet preview in WordPress admin was claiming the title would be just:

Verbier Ski School : Private Ski Lessons

I was very happy to have “Performance Verbier” added to the end – infact I preferred it (for this page) – but I wanted a space before it.

In the past I’ve tinkered and tried different separators and updated defaults etc. and eventually ended up with something presentable. But this time I just wanted to get to the bottom of the issue as I was sure I couldn’t be the only one with this issue and there must be a solution – it must just be that I was doing something wrong.

Now, despite over 10 years of developing for WordPress I’ve never actually installed Yoast myself, I don’t think. So it’s possible that what I’m going to say is cited in the docs – but if it is then I’ve known various developers miss this step out.

In header.php you need to remove this code:

<title><?php
wp_title(' - ', true, 'right');
bloginfo('name');
?>
</title>

 

And replace it with just:

<title><?php wp_title(''); ?></title>

 

Once I’d done this (which you can do via Appearance > Editor if you don’t have FTP access / access to the server) the snippet preview in WordPress admin was accurate and I didn’t have any annoying issues with spaces.