B-219 Sec-55 Noida, India
+918010221733

How to make is_home() work in wordpress functions.php

You might have faced a situation when you are trying to is_home() inside functions.php but it is not working.

If you will use ‘init’ hook then is_home() will not work inside the functions.php . For using is_home() you will need to use ‘wp’ hook. Check the example below.

add_action( 'wp', 'check_home_condition' );

function check_home_condition() {
    if ( is_home() )
        add_action( 'wp_enqueue_scripts', 'add_my_scripts' );
}

function add_my_scripts() {
    ...
}
(Visited 418 times, 1 visits today)