post_type_supports()
Checks if the post type supports the specified feature (meta-box): title, editor, author, thumbnail...
The function is used to determine if a specific post_type (for example, 'post' or 'page') supports a feature such as editor, thumbnail, comments, and others.
To retrieve data, the global variable $_wp_post_type_features is used.
Used By: use_block_editor_for_post_type()
1 time — 0.000018 sec (very fast) | 50000 times — 0.04 sec (speed of light)
No Hooks.
Returns
true|false.
true- the post type supports the specified featurefalse- the feature is not supported or a non-existent feature is specified.
Usage
post_type_supports( $post_type, $feature );
- $post_type(string) (required)
- The name of the post type to check.
- $feature(string) (required)
The name of the feature to check. The feature is registered in the
supportsparameter of the register_post_type() function. It can be:title- title block;editor- content input block;author- author selection block;thumbnail- post thumbnail selection block. Requires support from the theme - add_theme_support('post-thumbnails').excerpt- quote input block;trackbacks- notification block;custom-fields- custom fields setup block;comments- comments block;revisions- revisions block (not displayed until there are revisions);page-attributes- attributes block for permanent pages (template and hierarchical relationship of posts, hierarchy must be enabled). Can be used instead.post-formats– post formats block, if they are enabled in the theme.attachment:audio– special for attachments.attachment:video– special for attachments.
Examples
#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() post type supports code WP 7.0
function post_type_supports( $post_type, $feature ) {
global $_wp_post_type_features;
return ( isset( $_wp_post_type_features[ $post_type ][ $feature ] ) );
}