Common WordPress Conditional Tags Explained
When working with WordPress’s conditional tags, some of the first you’ll need will be the is_page, is_single, and is_singular tags. These tags all have very similar concepts and the differences can seem very small, especially the is_single and is_singular tags. Here’s how I interpret these WordPress conditional tags.
The is_page function is the easiest to understand. This conditional tag returns either true or false (boolean), depending on whether a PAGE is being displayed. It only works with the pages post type. The is_page() function accepts the page ID, title, or slug as parameters. For example, the is_page(‘About’) checks if the page being displayed has the title “About”. You can also insert an array to pass multiple parameters.
Although not a focal point of this post, the is_attachment tag should be mentioned because it acts like the is_page function, except for attachments.
The is_single function is a boolean function that determines if what’s being displayed is a single post type OTHER THAN Pages or Attachments. Therefore, it will check Posts and any of your Custom Post Types. This function accepts the post ID, title, or slug (arrays work too).
Finally, the is_singular tag is sort of a combination of the previous three. It checks to see if ANY of the other three are being displayed. In code, the is_singular tag is equivalent to ‘is_page || is_attachment || is_single’. I find this function to be most useful when checking to see if a single Custom Post Type is being displayed. For example, is_singular(‘product’).
Amin Omer says
Thank you very much Mr. Ren Ventura for the clear and easy explanation.
Thanks for the clarification.These two tags are the two that I usually interchangeably used.
Hi Rudd. I’m glad the post cleared things up for you. There are a number of tags that are closely related in terms of syntax or concept (i.e. is_home vs. is_font_page) and it’s easy to confuse them.