Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've placed the following code in my functions.php file

if(!is_home()){ echo "Not Home";}
if(is_home()){ echo "Home";}

However, no matter what page I'm on, I get "Not Home", And I'm real sure I'm on the home page, but still get "Not Home". What am I missing?

share|improve this question
    
Did you add this just in functions.php, or in a function in functions.php? It's possible that it is just called too early, when WordPress has not yet decided whether it is on the homepage or not. –  Jan Fabry May 19 '11 at 15:47
    
Just in functions.php, not in a function. When I place it inside a function it works fine. Lesson learned. Thanks Jan! Can you convert your comment to an answer? –  Scott B May 19 '11 at 15:54
    
Downvoter. I'm pretty sure I have an idea who you are. At least have the courage to leave a reason. –  Scott B May 19 '11 at 16:24
    
The system includes a daily check for suspicious voting patterns. It is possible that the downvotes will be cleared by tomorrow. If the problem persists you can contact a moderator or the site owners, they can look at voting patterns (without needing to see who actually voted). –  Jan Fabry May 19 '11 at 16:54
    
In case you meant me: No, i wasn't the downvoter. And to prove that to you, I could downvote it too (just ask). :) And I leave you a reason for why I would downvote it too: Conditional checks are part of the global $wp_query (which you should already know - can't do anything without it, right?) and taking a look at the Action API tells you exactly when it gets build. Here's the reason why I didn't downvote it until now: I stepped in the trap myself more than once. –  kaiser May 19 '11 at 23:55
add comment

1 Answer

up vote 4 down vote accepted

If you just place it in functions.php, not in a function in functions.php, it will be called too early. WordPress includes functions.php before it parses the URL and determines whether you are actually on the homepage or not.

Since WordPress 3.1 there is an extra warning (only visibile if you enable WP_DEBUG) if you call these too early, to prevent these confusing situations.

share|improve this answer
    
thanks for your answer and explanation. I learned something new today. Apparently, there's a serial downvoter following me who doesn't have the courage to leave a name. –  Scott B May 19 '11 at 16:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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