How do test if a post is a custom post type?

I am looking for a way to test if a post is a custom post type. For example, in, say, the sidebar I can put in code like this:

 if ( is_single() ) {
     // Code here
 }

I want code testing for only a custom post type.

Here you are: get_post_type() and then if ( 'book' == get_post_type() ) ... as per Conditional Tags > A Post Type in Codex.

Leave a Comment