WordPress function to check if the current post is a custom post type
Just paste this code into your functions.php file:
function is_custom_post_type() {
global $wp_query;
$post_types = get_post_types(array('public' => true,'_builtin' => false),'names','and');
foreach ($post_types as $post_type ) {
if (get_post_type($post_type->ID) == get_post_type($wp_query->post->ID)) {
return true;
} else {
return false;
}
}
}
Once complete, we can use the function as display below.
P.S. : function can be used outside the loop:
if (is_custom_post_type()) {
//Current post is a custom post type
}
Just paste this code into your functions.php file:
function is_custom_post_type() {
global $wp_query;
$post_types = get_post_types(array('public' => true,'_builtin' => false),'names','and');
foreach ($post_types as $post_type ) {
if (get_post_type($post_type->ID) == get_post_type($wp_query->post->ID)) {
return true;
} else {
return false;
}
}
}
Once complete, we can use the function as display below.
P.S. : function can be used outside the loop:
if (is_custom_post_type()) {
//Current post is a custom post type
}