Home » Functions » is_single

The is_single function is a built-in WordPress function that is used to check if the current page being displayed is a single post. It returns true if the page is a single post, and false if it is not.

This function is commonly used in WordPress themes to conditionally display certain content or apply specific styles only on single post pages. For example, you may want to display a featured image or show related posts only on single post pages. By using the is_single function, you can easily achieve this.

Here’s an example usage of the is_single function:

if ( is_single() ) {
    // This code will only execute on single post pages
    // Display the featured image
    // Show related posts
    echo do_shortcode('[related_posts]');
} else {
    // This code will execute on any other page, such as the homepage or archive pages
    // Display a default image
    echo '<img src="default-image.jpg" alt="Default Image">';

In the example code above, the is_single function is used to conditionally display different content. If the current page is a single post, it will display the featured image and show related posts using a shortcode. If the page is not a single post (e.g., homepage or archive pages), it will display a default image instead.

By using the is_single function, you can easily customize the appearance and functionality of your WordPress theme based on whether the page being viewed is a single post or not.

Learn More on

Register an account to save your snippets or go Pro to get more features.