How to easily test if an entry is a custom post type

Simply paste the following function into your functions.php file:

function wpr_is_post_type($type){
    global $wp_query;
    if($type == get_post_type($wp_query->post->ID)) return true;
    return false;
}

Once done you can use the function in your themes:

if (wpr_is_post_type($type){
    ...
}

Thanks to John for submitting this cool function!

Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!

How to easily test if an entry is a custom post type

Leave a Reply

Your email address will not be published. Required fields are marked *