post_type_supports()WP 3.0.0

Check a post type's support for a given feature.

1 time — 0.000018 sec (very fast) | 50000 times — 0.04 sec (speed of light)

No Hooks.

Return

true|false. Whether the post type supports the given feature.

Usage

post_type_supports( $post_type, $feature );
$post_type(string) (required)
The post type being checked.
$feature(string) (required)
The feature being checked.

Examples

0

#1 Some examples of checks

Check whether the metabox thumbnail is provided for the post type page

if( post_type_supports( 'page', 'thumbnail' ) ){
	echo 'The post editing page has a "thumbnail" metabox.';
}

To check if posts support comments:

if ( post_type_supports( 'post', 'comments' ) ) {
	...
}

Or, if pages support excerpts:

if ( post_type_supports( 'page', 'excerpt' ) ) {
	...
}

Notes

  • Global. Array. $_wp_post_type_features

Changelog

Since 3.0.0 Introduced.

post_type_supports() code WP 6.1.1

function post_type_supports( $post_type, $feature ) {
	global $_wp_post_type_features;

	return ( isset( $_wp_post_type_features[ $post_type ][ $feature ] ) );
}