WordPress is_singular() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Conditional tag

Definition

In WordPress, is_singular() returns true on any single view. That means a single post, a Page, an attachment, or a single custom post type item.

Pass a post type name, or an array of names, to limit the check. With no argument, it matches all single views.

Syntax

Use it as the test of an if statement.

WordPress
if ( is_singular() ) {
  // code for the true path
} else {
  // code for the false path
}
CallWhat it does
is_singular()True on any single post, Page, attachment, or custom post.
is_singular( 'book' )True on a single book.
is_singular( array( 'post', 'page' ) )True on a single post or a Page.

A simple way to remember: singular means one item, whatever its type.

Full declaration
WordPress
is_singular( string|string[] $post_types = '' ): bool

Parameters

ParameterDescription
$post_typesOptional. A post type name or an array of names. Default is empty, which means any post type.

Return Value

Return ValueDescription
booltrue if the main query is for a single item of the given type, otherwise false.

WordPress Examples

Three short theme examples. Each one shows what prints on the true path and the false path.

Example 1 — Any single view

Load a script on posts and Pages, but not on archives.

WordPress
function mytheme_scripts() {
  if ( is_singular() ) {
    echo '<!-- single-view script -->';
  }
}
add_action( 'wp_head', 'mytheme_scripts' );

How It Works

  1. is_singular() is true on every single view.
  2. Archives and the blog index return false.
  3. The comment is printed only on single views.

Example 2 — One post type

Show a related box on a single book.

WordPress
<?php if ( is_singular( 'book' ) ) {
  echo '<p>More books by this author</p>';
} ?>

How It Works

  1. 'book' is the post type name.
  2. Only a single book returns true.
  3. Posts and Pages skip the box.

Example 3 — Post or Page

Match two types with an array.

WordPress
<?php if ( is_singular( array( 'post', 'page' ) ) ) {
  echo '<div class="reading-width">';
} ?>

How It Works

  1. The array holds two post types.
  2. The tag is true on a single item of either type.
  3. Attachments are not in the list, so they return false.

Frequently Asked Questions

It returns true or false (a bool). Use it inside an if statement.
is_singular() is true on posts, Pages, attachments, and custom post types. is_single() is for posts (and custom post types) but not Pages or attachments.
Yes. Pass the post type name, for example is_singular( 'book' ).
No. The blog index lists many posts, so it is not a single view.
Conditional tags need the main query. Call them in template files or on hooks such as wp or template_redirect, not directly at the top of functions.php.

Next: is_sticky()

Check if a post is a sticky post.

is_sticky() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

14 people found this page helpful