• Resolved broomy

    (@broomy)


    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?

    Thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • Kafkaesqui

    (@kafkaesqui)

    Let’s see the code you have so far.

    billh

    (@billh)

    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.

    Kafkaesqui

    (@kafkaesqui)

    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).

    Thread Starter broomy

    (@broomy)

    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?

    Kafkaesqui

    (@kafkaesqui)

    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.

    koeln

    (@koeln)

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

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

    Thread Starter broomy

    (@broomy)

    Great, thanks for your help.

    billh

    (@billh)

    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.

    Kafkaesqui

    (@kafkaesqui)

    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.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Title Errors’ is closed to new replies.