The Difference Between is_singular() and is_single()

Posted on: October 25, 2009 by Jeff Starr

You know that you can target single-view pages with the conditional tag, is_single():

<?php
if(is_single()) {

	// do something

} else {

	// do something else

}
?>

This is a great way to conditionally apply styles, scripts, and markup to single-view pages.

But did you know about the conditional tag, is_singular()? The is_singular() tag enables you to target single-view pages, regular page pages, and attachment pages all in one fell swoop.

So, instead of writing something like this:

<?php
if(is_single() || is_page() || is_attachment()) {

	// do something

} else {

	// do something else

}
?>

We can write this instead:

<?php
if(is_singular()) {

	// do something

} else {

	// do something else

}
?>

The is_singular() tag is what’s known as a “boolean” function, meaning that it returns one of two values, either TRUE or FALSE. No parameters are associated with this tag.

Now you know :)

Thumb for The Difference Between is_singular() and is_single()

Let's talk it out, folks.

  1. In the words of Keanu Reeves: Whoa!.

    #1
  2. Handy tip, always good to save some extra typing!

    #2
  3. Hassan said on October 26, 2009:

    I prefer to use (is_single() || is_page() || is_attachment()) cause it’s more readable. But, these little tips are the difference between a pro or a starter guy. Thanks for the tip!

    #3

Comments are closed. If you have something really important to add, contact us. Thank you!