Rafael Umbelino
Rafael Umbelino

Reputation: 810

is_home() || is_front_page() not working

I have already tried everything, and searched in every place. Why doesn't it work?

This is my functions.php, the page always show "else".

My code:

wp_reset_query();
if(is_home() || is_front_page())
    die("if");
die("else");

Upvotes: 1

Views: 4770

Answers (1)

Kevinvhengst
Kevinvhengst

Reputation: 1702

you can use a hook in your function.php to execute a piece of code before everything else like this:

add_action('wp', 'check_home');
function check_home() {
    if(is_home() || is_front_page()) {
        die("yes");
    } else {
        die("no");
    }
}

You should never just write php statements that stand on it's own in your functions.php file. Only use it to define functions that your want to use somewhere else in your code, or define hooks like actions and filters with corresponding functions.

If you want to know more about hooks read this

Upvotes: 4

Related Questions