Wordpress - How do test if a post is a custom post type?
if ( is_singular( 'book' ) ) {
// conditional content/code
}
The above is true
when viewing a post of the custom post type: book
.
if ( is_singular( array( 'newspaper', 'book' ) ) ) {
// conditional content/code
}
The above is true
when viewing a post of the custom post types: newspaper
or book
.
These and more conditional tags can be viewed here.
Here you are: get_post_type()
and then if ( 'book' == get_post_type() ) ...
as per Conditional Tags > A Post Type in Codex.
Add this to your functions.php
, and you can have the functionality, inside or outside of the loop:
function is_post_type($type){
global $wp_query;
if($type == get_post_type($wp_query->post->ID))
return true;
return false;
}
So you can now use the following:
if (is_single() && is_post_type('post_type')){
// Work magic
}