WordPress.org

Ready to get started?Download WordPress

Forums

Php help (5 posts)

  1. degmsb
    Member
    Posted 8 years ago #

    I am new to wordpress and I am trying to insert some php in my head template. What I hope to do is when the home page is live place a custom meta description in the page. If the home page is not live I want no meta description becasue the xfish_meta plug I use will control these pages. This is what I have currently:

    <?php if ( is_home() ) {?>
    <meta name="description" content="<?php if ( is_home() ) {
    bloginfo('name'); echo " - "; bloginfo('description');
    }}
    ?>" />

    This is working fine on the home page, but when I go to an individual post it leaves the "/> which I do not want. Can anyone help me fix this?

    Here is my test page:
    Home Page: http://degmsb0.tollfreepage.com

    Individual post with problem: http://degmsb0.tollfreepage.com/?p=20

    Thank you.

  2. jaseone
    Member
    Posted 8 years ago #

    Change it to:

    <?php if ( is_home() ) {?>
    <meta name="description" content="<?php if ( is_home() ) {
    bloginfo('name'); echo " - "; bloginfo('description');
    }
    echo "/>";
    }
    ?>"

  3. degmsb
    Member
    Posted 8 years ago #

    Thank you for the quick response. This almost works, but when the page is not my home page it places an extra quote mark in the page under the title. See here: http://degmsb0.tollfreepage.com/?p=20

    Secondly the description appears like this on the home page:

    <meta name="description" content="Motorcycle Helmets - This is a test blog/>"

    Instead I need it like the below with the quote inside the />

    <meta name="description" content="Motorcycle Helmets - This is a test blog “ />

    I tried to modify but could not get it to work.

    Do you have any other suggestions?

    Thank you again.

  4. jaseone
    Member
    Posted 8 years ago #

    Oh crap, stuffed up my copy & paste, try this instead sorry about that:

    <?php if ( is_home() ) {?>
    <meta name="description" content="<?php if ( is_home() ) {
    bloginfo('name'); echo " - "; bloginfo('description');
    }
    echo "\"/>";
    }
    ?>

  5. degmsb
    Member
    Posted 8 years ago #

    Worked Perfect, Thank you so much!!!

Topic Closed

This topic has been closed to new replies.

About this Topic