Spaces in Wordpress Titles

Discussion in 'PHP' started by JohnS0N, Jun 16, 2010.

  1. #1
    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.
     
    JohnS0N, Jun 16, 2010 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,901
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    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.
     
    sarahk, Jun 16, 2010 IP
  3. dabaR

    dabaR Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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:
     
    dabaR, Jun 17, 2010 IP