Languages: English • Türkçe • 日本語 中文(简体) • (Add your language)
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.
<?php is_singular( $post_types ); ?>
<?php
if ( is_singular() ) {
// show adv. #1
} else {
// show adv. #2
}
?>
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';
}
}
True when viewing a regular post.
is_singular( 'post' );
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' ) );
is_singular() is located in wp-includes/query.php.