is_front_page only works in theme file, and does not work in functions.php

That may be normal behavior, depending on how exactly you’re using is_front_page in your functions file.

If you use it inside the global scope of functions.php, it will not work.

Why? Because WordPress loads functions.php before the $wp_query object has been set up with the current page. is_front_page is a wrapper around around $wp_query->is_front_page(), and if the query hasn’t been set up, it’s always going to return false (or throw a warning, if you have wp_debug on.

From the codex:

Warning: You can only use conditional query tags after the init action
hook in WordPress. For themes, this means the conditional tag will
never work properly if you are using it in the body of functions.php,
i.e. outside of a function.

http://codex.wordpress.org/Conditional_Tags

Leave a Comment