Add action hook conditionally – only when home.php in use

Use is_home instead, as is_page_template will not work for home.php as its technically not a page template in the traditional sense.

add_action('template_redirect', 'are_we_home_yet', 10);
function are_we_home_yet(){
        if ( is_home() ) {
        //your logic here
    }
}

Revised:

add_action('template_redirect', 'are_we_home_yet', 10);
function are_we_home_yet(){
        global $template;
        $template_file = basename((__FILE__).$template);
        if ( is_home() && $template_file="home.php" ) {
        //do your logic here
    }
}

The revised answer is actually what you really need, it will check if you are on the home page, in addition to getting the template file being included and check to see if that file is in fact your home.php file and if so, you can go about your logic…

Leave a Comment