The website I am working on has a different footer on the home page to all the other pages on the site.
However the footer does not appear on any of the pages at all.
here is the code I am using:
<?php if ( is_home() ) {
// This is a homepage
?>
<div id="footer"> This is home page</div>
<? } else { ?>
<div id="footer">This is not a homepage</div>
<?}?>
Is my syntax wrong? Why doesn’t this code work?
Thank you all in advance.
2 things I can think of here:
<?php
open tagsConsider revising the code to following:
Unless you’re using an old version of php, you might want to switch
<? } else { ?>
to<?php } else { ?>
– note that I’m using a<?php
instead of just<?
.As for the
is_home()
, you might want to read up on the following link: http://codex.wordpress.org/Function_Reference/is_homeIt seems as if
is_home()
sometimes isn’t the same thing asis_frontpage()
, which means that you in some cases need to useis_frontpage()
instead.Good luck!
Using
<?php
open tags is one of the “best practices” in WordPress coding. Also, consider using<?php get_footer('footer-variant') ?>
instead of conditional statements in your footer.php. After callingget_footer('my-footer')
,footer-my-footer.php
file will be used.