WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/is singular

Description

This conditional tag checks if a singular post is being displayed, which is the case when one of the following returns true: is_single(), is_page() or is_attachment(). If the $post_types parameter is specified, the function will additionally check if the query is for one of the post types specified.

Usage

<?php is_singular$post_types ); ?>

Parameters

$post_types
(string/array) (optional) Post type or types to check in current query.
Default: None

Return Values

(boolean) 
True on success, false on failure.

Examples

Different Sidebar Ads in Singular Page

<?php
if ( is_singular() ) {
  // show adv. #1
} else {
  // show adv. #2
}
?>

Usage With Hook in Custom Function

You can use the conditional tag in a custom function with a WordPress or theme specific hook in your functions file

add_action( 'loop_start', 'your_function' );
function your_function() {
if ( is_singular() ) {
echo 'Hello World';
    }
}

Default Post Type

True when viewing a regular post.

is_singular( 'post' );

Custom Post Types

When any of the following return true: is_single(), is_page() or is_attachment().

is_singular();

True when viewing a post of the Custom Post Type book.

is_singular( 'book' );

True when viewing a post of the Custom Post Type newspaper or book.

is_singular( array( 'newspaper', 'book' ) );

Notes

Change Log

  • Since: 1.5.0
  • 3.0.0: $post_types parameter was added.

Source File

is_singular() is located in wp-includes/query.php.

Related

See also index of Function Reference and index of Template Tags.