When using conditional tags in WordPress, if you hook in too early the conditional tags don’t work because WordPress hasn’t determined their values yet.
The earliest hook for conditional tags
Hook wp
Example Hook Function to wp
add_action( 'wp', 'function_that_uses_is_front_page' );
Examples of conditional tags
is_home()
main blog pageis_front_page()
front of the site is displayedis_admin()
is_admin_bar_showing()
is_single()
single Post (or attachment, or custom Post Type) page is being displayed. (False for Pages)is_post_type_archive()
comments_open()
is_page()
is_category()
is_tag()
is_tax()
has_term()
is_author()
is_archive()
any type of Archive page is being displayed. Category, Tag, Author and Date based pages are all types of Archives.is_search()
is_404()
is_paged()
is_attachment()
is_singular()
true for any is_single(), is_page(), or is_attachment().is_main_query()
true when the current query (such as within the loop) is the “main” query.
Leave a Reply