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 put a if(is_home()) bit in my theme's functions.php and it doesn't seem to work. The function containing this bit is called on init so is_home should work already.

share|improve this question
    
Thanx for tags! –  naugtur Aug 23 '10 at 10:06

2 Answers 2

up vote 8 down vote accepted

is_home() won't work until wp_query is run. The earliest hook you can use where is_home will work is 'parse_query', but 'template_redirect' would be better.

share|improve this answer
    
Technically, 'parse_query' runs before 'wp' and is the absolute earliest you can check for is_home() with any certainty. –  John P Bloch Aug 19 '10 at 15:03
    
wp() is called after init, so template_redirect is the first hook, for more options and a better view, see: toolpress.de/… –  hakre Aug 19 '10 at 15:08
    
You misunderstood me, hakre. 'parse_query' and 'wp' are action hooks too, and that's what I was referencing. –  John P Bloch Aug 19 '10 at 16:47
    
oh, no, not at all. I just wanted to underline what you wrote. I think your answer is just totally right. –  hakre Aug 20 '10 at 9:54

To follow up on John's answer: Add a call to said function on one of the hooks mentioned by John and hakre.

Add, e.g., the following to your functions.php:

<?php
function my_function_name(){
  if(is_home()) do_something();
}

add_action('template_redirect', 'my_function_name');
?>

EDIT: I misread your question at first -- it looks like you've got a function encapsulating the code already, it's just that you're firing on the wrong hook. Either break that section out into a separate function and have it fire at template_redirect, etc., or change where you're hooking in the first place.

share|improve this answer

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.