I have this following code for the title tag on my wordpress website: <title><?php if (is_front_page()) { bloginfo('name'); ?><?php } elseif (is_category() || is_page() || is_single()) { ?> <?php } ?><?php wp_title(''); ?></title> Now if the page is front page in my source code I get the title printed correctly like: <title>My Front Page Title Rocks</title> Code (markup): But if the page is a single page, post, category or archive my titles in the source code look like this: <title> Other Titles Appear Like This. With Spaces In The Beginning & End Of The Title </title> Code (markup): Can someone tell me what's going on? If you need the url, please say so and I'll pm it to you. Cheers.
I would prefer to see that put like this <title><?php if (is_front_page()) bloginfo('name'); wp_title(''); ?></title> PHP: With the code you have given all the elseif does is print the spaces. Can't explain the spaces at the end though but they're not as important.
You could use the trim function, http://php.net/manual/en/function.trim.php. You would use it something like... trim(wp_title('', true)) PHP: