WordPress.org

Ready to get started?Download WordPress

Ideas

Add "is_post_type()" function

  1. ahuggins
    Member

    12345

    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') {

    wp_deregister_script('script_name');
    wp_deregister_style('css_name');

    }

    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: 2 years ago #
  2. Ipstenu (Mika Epstein)
    Half-Elf Support Rogue & Mod

    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: 2 years ago #
  3. Use is_singular( 'post_type' ) and is_post_type_archive( 'post_type' ).

    Posted: 2 years ago #
  4. ahuggins
    Member

    12345

    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: 2 years ago #
  5. Ipstenu (Mika Epstein)
    Half-Elf Support Rogue & Mod

    I think is_post_type will be deprecated eventually.

    Posted: 2 years ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    4 Votes
  • Status

    This idea is under consideration