Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Darren Healy
seal-mask
.a{fill-rule:evenodd;}techdegree
Darren Healy
Front End Web Development Techdegree Student 23,565 Points

Write out a conditional statement that tests if a page is the front page in WordPress

I thought this was the answer but I've been told it is wrong:

<?php if ( is_front_page() ): ?>

Am I making a silly mistake?

Ron McCranie
Ron McCranie
7,837 Points

I looked at the Wordpress Codex looks correct to me. But I'm not a Wordpress guru so there may be certain instances where it's returning false and using is_home() would be the better option. There may be something wrong somewhere else in your code.

3 Answers

I got it with

if( is_front_page() )

You don't need the php part since it isn't a complete statement.

Mahesh Sangam
Mahesh Sangam
71 Points

<?php if ( is_front_page() ){

//statement } else{

//statement }

?>

Have you already set a front page in the admin panel Settings>Reading? I believe that function only checks for that particular page.