WordPress.org

Ready to get started?Download WordPress

Codex

Function Reference/is singular

Contents

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
}
?>

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.