[resolved] Title Errors (10 posts)

  1. Broomy
    Posted 9 years ago #

    This is driving me mad! I'm trying to make the bloginfo('name') appear in the title tag on the homepage and the title of the post only on the post pages without anythink else. I've tried following the syntax but everything I try ends with an error (I admit i'm not the best with code!). Could anyone point out how to do this?


  2. Kafkaesqui

    Posted 9 years ago #

    Let's see the code you have so far.

  3. billh
    Posted 9 years ago #

    If you are going to use the blog name in the title, you need to use the get_bloginfo('name') function as it is defined within the head HTML tags. The bloginfo() template tag is used only within the body HTML tags.

  4. Kafkaesqui

    Posted 9 years ago #

    Sorry billh, that's not correct.

    bloginfo() echoes or prints the value for the argument option that is passed to it.

    get_bloginfo() returns the value, so you could assign it to a PHP variable or such.

    That's the only real difference between the two functions. Either can be used anywhere within ones templates (well, within reason).

  5. Broomy
    Posted 9 years ago #

    Thanks for the replies. I now have it working as follows:

    <?php if (is_home()){bloginfo('name');}else{ ?><?php wp_title(' '); ?><?php } ?>

    Does this look right?

  6. Kafkaesqui

    Posted 9 years ago #

    If you're asking if the logic is correct, that depends on if it's outputting the data the way you want it. You may combine your php tags:

    <?php if (is_home()) { bloginfo('name'); } else { wp_title(' '); } ?>

    but beyond that, things look fine from here.

  7. koeln
    Posted 9 years ago #

    You do not need the {} if there is just one line of code:

    <?php if (is_home()) bloginfo('name'); else wp_title(' '); ?>

  8. Broomy
    Posted 9 years ago #

    Great, thanks for your help.

  9. billh
    Posted 9 years ago #

    Kafkaesqui, when I read his question, I assumed incorrectly that he was working in the HTML head section. In my experience, flaky things happen when you use the bloginfo() template tag there because nothing between the <head>...</head> tags is displayed to the browser except what is between the <title>...</title> HTML tags. After reading his posts further, I see he is working in the HTML body section, using the wp_title() template tag which is completely different.

  10. Kafkaesqui

    Posted 9 years ago #

    billh, ?

    Broomy noted in the first post the code is for the title tag, which is in the <head> of an X/HTML document.

    I'm not sure what flakiness you've run across with bloginfo(), but my own templates make numerous calls to it throughout the <head>. And not just to display my blog's name, but also for providing the default stylesheet url, and outputting 'alternate' link tags for my syndication feeds.

Topic Closed

This topic has been closed to new replies.

About this Topic