Home >> Latest Articles >> Common WordPress Conditional Functions

Common WordPress Conditional Functions

Here are some common WordPress conditional functions. Note that this is not an inclusive list. Conditional Tag:
  • is_home() – blog home
  • is_front_page() – site front page
  • is_single() – single post
  • is_page()
  • is_attachment() – if on an attachment page (such as an image)
  • is_singular() – returns true for any is_single, is_page, or is_attachment
  • is_category() – when a category page is being displayed
  • is_tag() – when a tag page is being displayed
  • is_archive() – returns true if on archive page
  • is_search() – returns true if on search page
  • is_author() – when author page is being displayed
Other:
  • is_404() – when page not found is being displayed
  • is_paged() – if archive or main page is split into several page, this returns true on second and subsequent pages.
  • is_preview() – if displayed in preview mode.
  • is_sticky() – if the post is sticky
  • has_tag() – pass in tag or array of tags, returns true if post has this tag
  • has_excerpt() – if the post has an excerpt
  • has_post_thumbnail() – returns true if post has Featured image
  • is_page_template() – pass in a template file with extension, returns true if this template is being used
Archives:
  • is_date() – when a date-based archive page is being displayed
  • is_year()
  • is_month()
  • is_day()
  • is_time()
  • is_new_day()
Taxonomy:
  • is_tax() – when any taxonomy archive page is being displayed
  • has_term() – check if post has certain terms for taxonomy
  • taxonomy_exists()
  • is_taxonomy_hierarchical()
Admin:
  • is_admin()
  • is_user_logged_in()
  • is_super_admin() – returns true if user is super admin in a Multi-site.  If not in Multi-site, returns true if user is an admin
  • is_admin_bar_showing()
Post type:
  • is_post_type_archive() – pass in a post_type, returns true if archive of that post type
  • is_post_type_hierarchical() – pass in a post_type, returns true if this post_type was registered as having support for hierarchical
Comments and Pings:
  • is_comments_popup() – true when in comments popup window
  • comments_open()
  • pings_open()
  • is_trackback()
  • is_feed()
Misc:
  • has_nav_menu() – pass in menu location slug, returns true if this location has menu
  • in_the_loop() – when inside the loop
  • is_main_query()
  • is_active_sidebar() – pass in the sidebar name, id, or number, returns true if this sidebar is being used.
  • is_dynamic_sidebar() – True if the current sidebar has active widgets
  • is_active_widget()
  • is_blog_installed()
  • is_rtl()
  • is_multisite() – if current site is in a Multi-site install
  • is_main_site() – if current site is the main site in a multi-site install
  • is_child_theme()
  • current_theme_supports()
  • is_multi_author() – returns true if more than one author on this site. Returns false if one or no authors.
  • wp_attachment_is_image() – returns true if the attachment extension is .jpg, .jpeg, .gif, or .png.
  • wp_script_is() – Determine if a script has been registered, enqueued, printed, or is waiting to be printed.
If exists:
  • email_exists() –  check whether or not a given email address ($email) has already been registered to a username, and returns that users ID
  • username_exists() – Returns the user ID if the user exists or null if the user doesn’t exist.
  • post_type_exists()
  • taxonomy_exists()
  • term_exists()
Plugin:
  • is_plugin_active()
  • is_plugin_active_for_network()
  • is_plugin_inactive()
  • is_plugin_page()
     
Full Stack Tutorials

Author | Blogger @FullStackTutorials | View all articles