• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Programming / WordPress Conditional Tags Earliest Hook

WordPress Conditional Tags Earliest Hook

Last updated on April 27, 2014 by Sal Ferrarello

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 page
  • is_front_page() front of the site is displayed
  • is_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.
Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit

Filed Under: Programming Tagged With: WordPress

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in