Post type targeting

If you need custom displaying for different registered post types, you can use this trick:

$post_type = get_post_type( $post );
if ( is_single() &&  $post_type == 'your-post-type' ){
	//what to be shown on single 'your-post-type' "page";
} else {
       //what to be shown on every else single post "page";
}

you can use the same method on archive pages, by replacing the is_single() with is_archive(). Like an universal method you can try using,

$post_type = get_post_type( $post );
if ($post_type == 'your-post-type' ){

} else {

}

with same results, but if you want to be sure use the first example.

A more elegant solution is to use WordPress is_singular() function, but there are reported cases in which this would not work, …but is good to have more options from which to choose.

Leave a Reply

Your email address will not be published. Required fields are marked *

1 × 7 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.