How To: Test for a WordPress Custom Post Type

There instances where a WordPress developer may need to test whether a specific post is a Custom Post Type. You can test whether a post is a specific Custom Post Type from within the loop, outside of the loop, or from within the Single Post view (single.php, single-*.php, and more).

Testing for a Custom Post Type from within The Loop

In this example, we will be using the get_post_type() function to determine whether a post is a ‘photo’ or ‘illustration’ Custom Post Type.

Testing for a Custom Post Type within single.php

The built-in WordPress function is_singular() will test whether any of the following is true for a page: is_single(), is_page() or is_attachment(). The is_singular() function also has the ability to test whether a page is a specific type. You can test whether a page is a blog post or a ‘photo’ type in the following example: