WordPress判断是否为指定post-type

WordPress判断是否为指定post-type

/**
 * Function to make it possible to query on is_post_type()
 * 
 * source: http://wordpress.stackexchange.com/a/22166/2015
 */
function is_post_type( $type ) {
    global $wp_query;
    if ( $type == get_post_type( $wp_query->post->ID) ) return true;
    return false;
}
/**
 * EXAMPLE
 * Now you can enqueue styles or scripts only for a specific Custom Post Type
 */
if ( is_single() && is_post_type( 'cpt-name' ) ) {
    // the script and/or style you want to enqueue
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据