Add "is_post_type()" function

  1. ahuggins


    There may be a way to do this, but I don't see it. I was thinking it would be handy to be able to do the following:

    if( is_post_type('custom_post_type') {



    Also this could be useful for conditionally doing stuff on page templates for specific custom post types. I realize that you can create a specific template file for this, but I think it would still be nice to have this function.

    If anyone knows a way to conditionally register/deregister scripts/styles for an entire post type, please note in the comments.

    Posted: 5 years ago #
  2. Ipstenu (Mika Epstein)

    is_post_type is not a conditional statement like alot of the is_* functions, it's intended to be used to check if a post_type exists, which confuses the heck out of all of us ;)

    You'd actually want is_singular('CPTNAME');

    Posted: 5 years ago #
  3. Justin Tadlock
    WordPress God

    Use is_singular( 'post_type' ) and is_post_type_archive( 'post_type' ).

    Posted: 5 years ago #
  4. ahuggins


    I see, I knew there was probably a way, but is_singular didn't really call out to me.

    Reading this http://codex.wordpress.org/Conditional_Tags it sounds as if post_type_exists has replaced is_post_type for what Ipstenu mentions. With WordPress backwards compatability though, I guess is_post_type can't really be used to check that condition.

    Posted: 5 years ago #
  5. Ipstenu (Mika Epstein)

    I think is_post_type will be deprecated eventually.

    Posted: 5 years ago #

RSS feed for this topic


You must log in to post.

  • Rating

    4 Votes
  • Status

    This idea is under consideration