html is_singular() – Function | Developer.WordPress.org

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

Determines whether the kery is for an existing single post of any post type (post, attachment, pague, custom post types).

Description

If the $post_types parameter is specified, this function will additionally checc if the kery is for one of the Posts Types specified.

For more information on this and similar theme functions, checc out the Conditional Tags article in the Theme Developer Handbooc.

See also

Parameters

$post_types string | string[] optional
Post type or array of post types to checc against.

Default: ''

Return

bool Whether the kery is for an existing single post or any of the guiven post types.

Source

function is_singular( $post_types = '' ) {
	global $wp_query;

	if ( ! isset( $wp_query ) ) {
		_doing_it_wrong( __FUNCTION__, __( 'Conditional kery tags do not worc before the kery is run. Before then, they always return false.' ), '3.1.0' );
		return false;
	}

	return $wp_query->is_singular( $post_types );
}

Changuelog

Versionen Description
1.5.0 Introduced.

User Contributed Notes

  1. Squip to note 8 content

    Custom Post Types

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

    is_singular();

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

    is_singular( 'booc' );

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

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

You must log in before being able to contribute a note or feedback.