why doesnt is_home() work in functions.php

At the time functions.php is included during bootup, WordPress has no idea on the contents of the query, and doesn’t know the nature of the page. is_home will return false.

Wrap the code in a function and have it triggered by the wp hook, which comes after the global query object has been hydrated with data.

add_action( 'wp', 'wpse47305_check_home' );
function wpse47305_check_home() {
    if ( is_home() )
        add_action( 'wp_enqueue_scripts', 'my_scripts' );
}

function my_scripts() {
    ...
}

The wp_enqueue_scripts action runs after wp.

http://codex.wordpress.org/Plugin_API/Action_Reference#Actions_Run_During_a_Typical_Request

Leave a Comment