How to modify Wordpress Title Tag

Discussion in 'PHP' started by Bohol, Mar 13, 2008.

  1. #1
    I would like to see a single post of my wordpress site having a title only specified in the source code, so that what appears in the browser would be the same that would appear in the source code.

    Example:

    Browser: Google Buys Microsoft

    Source code: <title>Google Buys Microsoft</title>

    What I have now is website title and title of the post in the source code, which is not good.

    Thanks for your help.
     
    Bohol, Mar 13, 2008 IP
  2. Edynas

    Edynas Peon

    Messages:
    796
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #2
    When you open the template file look for the part where your header is made. If you have a file called header.php start there

    Take a look at the code and see if you find this line or something like it
    <title><?php bloginfo('name'); ?> <?php if ( is_single() ) { ?> &raquo; Blog Archive <?php } ?> <?php wp_title(); ?></title>
    Code (markup):
    Replace it with
    <title><?php if ( is_single() ) { wp_title();}else{ bloginfo('name');}?></title>
    Code (markup):
     
    Edynas, Mar 13, 2008 IP
    Bohol likes this.
  3. Bohol

    Bohol Peon

    Messages:
    2,680
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi Edynas,

    Thank you so much. I will deploy this change and see if it works.
     
    Bohol, Mar 13, 2008 IP
  4. Bohol

    Bohol Peon

    Messages:
    2,680
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I just finished implementing the code suggested above by Edynas and this is what I got from my source code in the browser:

    <title> &raquo; Title of the Article Here Sample</title>

    The additional characters ( &raquo; ) seem unrelated?
     
    Bohol, Mar 13, 2008 IP
  5. Edynas

    Edynas Peon

    Messages:
    796
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yup you should also remove that part in the code
     
    Edynas, Mar 13, 2008 IP
  6. Bohol

    Bohol Peon

    Messages:
    2,680
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hi Edynas,

    I just added the code that you provided, nothing else, and that's what I got.

    I can't figure out why those extra characters appear in the source code when I couldn't see them in the header file.
     
    Bohol, Mar 13, 2008 IP
  7. Edynas

    Edynas Peon

    Messages:
    796
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #7
    show me the code from the template that is in the header between the <title> tags
     
    Edynas, Mar 13, 2008 IP
  8. proxywhereabouts

    proxywhereabouts Notable Member

    Messages:
    4,027
    Likes Received:
    110
    Best Answers:
    0
    Trophy Points:
    200
    #8
    proxywhereabouts, Mar 13, 2008 IP
  9. walkere

    walkere Active Member

    Messages:
    112
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #9
    It's the wp_title() function call.

    Wordpress designed wp_title() to be used in conjunction with the blog name - so that a normal title would be "My Blog >> Article Name."

    You can specify what character appears by passing a parameter to wp_title(). The default is the &raquo; you got. If you pass a blank string to wp_title(), it might still use the default - but if you pass a space (' '), it should print just the space.

    Try either of these as the wp_title() function call and see what happens...

    wp_title('');
    wp_title(' ');
    PHP:
    Good luck,
    - Walkere
     
    walkere, Mar 13, 2008 IP
    Bohol likes this.
  10. Bohol

    Bohol Peon

    Messages:
    2,680
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Hi Walkere,

    I use this one: wp_title(''); and I got this result:

    <title> Will Google Buy All Online Advertising Networks?</title>

    So there is a white space before "Will Google....."

    How can we remove that white space, Walkere?
     
    Bohol, Mar 13, 2008 IP