0

I have some HTML code wrapped in a div tag that I'd like to place on the homepage.

Because I use a static page for a homepage, I'm guessing I should use is_front_page() and I should place the desired code in footer.php

This is what I have now in footer.php (just the snippet we need):

<?php>
 if (is_front_page()) 
  {
    //div html here
  }
?>
</body> </html>

What am I doing wrong here? Should I use echo in the php? Or should I use an OR statement in the IF (is_home OR is_front_page)

  • could you please elaborate whether you want that to display "html"code on all pages or just on homepage. Also do you have header.php file in you themes folder ? – Karishma Ramchandani Dec 26 '14 at 4:46
  • I think there is no is_home_page function. Where have you put your code? – Nilambar Dec 26 '14 at 10:49
  • That was a typo, I meant is_front_page, but they already fixed my problem. I didn't do the php syntax right, I'm a total newbie to php so I made many mistakes. – user3768524 Dec 26 '14 at 12:23
0

if you are just trying to put HTML inside PHP, just close PHP and wrap with HTML

<?php if ( is_front_page() ) { ?>
    <div>
        HTML Code
    </div>
<?php } ?>

And use is_front_page

  • It still doesn't work. When I just place my div html in the footer.php in the <body> tag it works - but on all pages. When I put the div tag in this php you gave me, it doesn't work. Where should I place this php anyway? I tried doing it in the body, html and outside those tags but still didn't work. – user3768524 Dec 25 '14 at 23:36
  • Can you post your complete code so that, I can let you know. Please make sure, you try with is_home() as well. Thanks – Suresh KUMAR Mukhiya Dec 25 '14 at 23:42
  • 2
    Corrected the code. Try it now – Robert hue Dec 26 '14 at 3:55
  • It works now, Robert. Thanks. Can I edit the if statement to my likings? Putting something like if (is_front_page() || is_single() ) so they display on homepage and on single posts page? – user3768524 Dec 26 '14 at 6:12
  • Yes you can do that, it will work. But keep PHP syntax correct otherwise it will not work. – Robert hue Dec 26 '14 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.