is_singular
Is the query for an existing single post of any post type (post, attachment, page, .
Description
is_singular( (string) $post_types = '' );
.. )?
If the $post_types
parameter is specified, this function will additionally check if the query is for one of the Posts Types specified.
Parameters (1)
- 0. $post_types — Optional. (string) =>
''
- Post type or array of post types. Default empty.
Usage
if ( !function_exists( 'is_singular' ) ) { require_once ABSPATH . WPINC . '/query.php'; } // Optional. Post type or array of post types. Default empty. $post_types = ''; // NOTICE! Understand what this does before running. $result = is_singular($post_types);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/query.php
- function is_singular( $post_types = '' ) {
- global $wp_query;
- if ( ! isset( $wp_query ) ) {
- _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
- return false;
- }
- return $wp_query->is_singular( $post_types );
- }