I’m using wordpress, and I’m having a hard time with a simple php code I want to add in footer.php to display a “|” symbol with 20px of margin and a url only on the site frontpage:
<?php
if(is_front_page()){
echo "<span style='margin: 0 20px;'>|</span><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>";
With the code above, I’m getting a php error:
PARSE ERROR: SYNTAX ERROR, UNEXPECTED ‘HTTP’ (T_STRING), EXPECTING ‘,’ OR ‘;’
This, is working:
<?php if( is_front_page() ) echo '<a href="http://www.w3schools.com" target="_blank">Visit W3Schools</a>';?>
And this, is working too:
<?php
if(is_front_page()){
echo "<span style='margin: 0 20px;'>|</span>";
}
?>
But somehow I can’t combine these two codes. What am I missing here?
You are going out of “PHP” with the double quote there. You can use this:
You had to use single quotes. You can’t use both when going into “String” mode. If you want to use double quote you have to escape it like (with a
):
The reason it is being commented out is because of your quotes. You have to either use single quotes around your double quotes or escape your quotes.
Here:
You need to escape
"
characters with