Last Updated: September 09, 2019
·
1.987K
· bainternet

Simple Function to check for post type

Here is a simple usful function i use to check for a specific post type:

function is_post_type($type='post') {
    global $post_type,$typenow;

    if (isset( $_GET['post_type'] )&& $_GET['post_type'] == $type 
        ||  isset( $post_type ) && $post_type == $type) 
        ||  isset( $typenow ) && $typenow == $type) 
        return true; // return true if on a page of type $type

    return false;
}

usage:

if (is_post_type('slider')){
    // the post type is slider :)
}

1 Response
Add your response

WordPress provides the is_singular() function for checking the current post type(s):

http://codex.wordpress.org/Function_Reference/is_singular

Hope it's useful :)

over 1 year ago ·