Why are There Spaces In Front of my Post Title?

Posted on Jul 13, 2011 in WordPress | 0 comments

Have you ever noticed your site title looks like this? ” My Post | My Website” instead of “My Post | My Website”

Somewhere in the PHP code of your website (which you can find under Appearance > Editor), you will likely find calls to the wp_title() function.

A sample call may look like this:

That results in showing the blog title with a separator (the ‘|’ character) to the right of the title… with a space before and after. In this case, the code is assuming that your blog name would come after that.

The problem is when you make a call like this:

That has no separator character (perhaps the site only shows the post title, or a separator is added elsewhere). The problem is that wp_title still adds blank spaces!

The solution is easy, but perhaps not obvious. Simply wrap the function call in trim(), like so:

 

Don’t forget the closing parenthesis on the end. This should eliminate those leading blanks in your title bar.

Submit a Comment

Manage your comment subscriptions