• Hi, I’m having a hard time with this simple php code I want to add in footer.php (child theme):

    <?php if(is_front_page()){
    echo "<a href="http://www.w3schools.com" target='_blank' title='W3C'>Visit W3Schools</a>";
    			}
    ?>

    The following characters are displayed in green by my txt editor as if they were comments:

    " target='_blank' title='W3C'>Visit W3Schools</a>";

    What am I missing here?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Try:

    <?php if( is_front_page() ) echo '<a href="http://www.w3schools.com" target="_blank">Visit W3Schools</a>';?>

    Thread Starter PODxt

    (@podxt)

    Thank you it’s working. Now if I want to add some margins, how can I make this code work:

    <?php
    if(is_front_page()){
    	echo "<span style='margin: 0 20px;'>|</span><a href="http://www.w3schools.com" target="_blank">Visit W3Schools</a>";
    }
    ?>
    <?php
    if(is_front_page()){
    	echo "<span style='display:inline-block; margin: 0 20px;'>|</span><a href="http://www.w3schools.com" target="_blank">Visit W3Schools</a>";
    }
    ?>
    Thread Starter PODxt

    (@podxt)

    Thanks but it’s not working. Everything from

    ” target=”_blank”>Visit W3Schools”;

    is marked in green as if it was a comment. I get a php error PARSE ERROR: SYNTAX ERROR, UNEXPECTED ‘HTTP’ (T_STRING), EXPECTING ‘,’ OR ‘;’

    Thread Starter PODxt

    (@podxt)

    This code works:

    <?php
    if(is_front_page()){
    echo "<span style='margin: 0 20px;'>|</span>";
    }
    ?>

    but when I try to add the url to this code, everything is breaking.

    Why did you change the code I originally gave you above?

    Thread Starter PODxt

    (@podxt)

    I didn’t, I tried your code exactly as it is and it didn’t work. I’m just trying things and notice the code in my last post works but I can’t add a url to it for some reason.

    See
    http://imageshack.com/a/img823/9951/x00g.png

    I’m getting:
    PARSE ERROR: SYNTAX ERROR, UNEXPECTED ‘HTTP’ (T_STRING), EXPECTING ‘,’ OR ‘;’

    be aware when to use single or double quotes;

    example:
    single quotes around the echo string, with double quotes within the string, should work:

    <?php
    if(is_front_page()){
    	echo '<span style="display:inline-block; margin: 0 20px;">|</span><a href="http://www.w3schools.com" target="_blank">Visit W3Schools</a>';
    }
    ?>
    Thread Starter PODxt

    (@podxt)

    Thanks!

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

The topic ‘Simple php in footer not working’ is closed to new replies.