Yes it should work in the header file just like normal. Try using a standard IF statement instead of shorthand:
if( is_front_page() ){
echo 'Front page!';
}
You must have it configured in the settings to use:
A static page (select below)
instead of Your latest posts
If you want is_front_page()
to only return TRUE when viewing the page you select from the dropdown for Front Page (which it sounds like you do)
You can then use is_home()
if a static page is set for the front page of the site, this function will return true only on the page you set as the “Posts page”.
https://developer.wordpress.org/reference/functions/is_home/
Whether is_home() or is_front_page() return true
or false
depends on the values of certain option values:
get_option( 'show_on_front' )
: returns either'posts'
or'page'
get_option( 'page_on_front' )
: returns theID
of the static page assigned to the front pageget_option( 'page_for_posts' )
: returns theID
of the static page assigned to the blog posts index (posts page)
When using these query conditionals:
- If
'posts' == get_option( 'show_on_front' )
:- On the site front page:
is_front_page()
will returntrue
is_home()
will returntrue
- If assigned, WordPress ignores the pages assigned to display the site front page or the blog posts index
- On the site front page:
- If
'page' == get_option( 'show_on_front' )
:- On the page assigned to display the site front page:
is_front_page()
will returntrue
is_home()
will returnfalse
- On the page assigned to display the blog posts index:
is_front_page()
will returnfalse
is_home()
will returntrue
- On the page assigned to display the site front page: