The add_post_type_support() WordPress PHP function registers support of specific features for a post type. Core features correspond to functional areas of the edit screen, like the editor, a meta box, or features like ‘title’, ‘editor’, ‘comments’, ‘revisions’, ‘trackbacks’, ‘author’, ‘excerpt’, ‘page-attributes’, ‘thumbnail’, ‘custom-fields’, and ‘post-formats’.
Usage
Here’s a basic example of how to use this function:
add_post_type_support( 'my_post_type', 'comments' );
This will enable comments for the post type ‘my_post_type’.
Parameters
- $post_type (string) – Required. Specifies the post type for which to add the feature.
- $feature (string|array) – Required. The feature being added. Can be an array of feature strings or a single string.
- $args (mixed) – Optional. Extra arguments to pass along with certain features.
More Information
See WordPress Developer Resources: add_post_type_support()
This function is still active and there’s no deprecation as of the latest update.
Examples
Adding Multiple Features
Add multiple features (‘author’, ‘excerpt’) to a post type ‘my_post_type’.
add_post_type_support( 'my_post_type', array( 'author', 'excerpt' ) );
Adding Feature with Additional Arguments
Add a feature ‘my_feature’ with extra arguments to a post type ‘my_post_type’.
add_post_type_support( 'my_post_type', 'my_feature', array( 'field' => 'value' ) );
Enabling Excerpts for Pages
Add support for excerpts in pages.
add_action('init', 'wpdocs_custom_init'); function wpdocs_custom_init() { add_post_type_support( 'page', 'excerpt' ); }
Adding Featured Images to Pages
Unfortunately, just adding post type support for ‘thumbnail’ won’t enable featured images for pages. You need to add theme support for ‘post-thumbnails’.
add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );
Enabling Support for a Specific Page
To enable add_post_type_support
for a specific page (e.g., page with ID 123), use the following:
global $pagenow; if( ($pagenow == 'post.php') && (isset($_GET['post'])) ){ $page_id = 123; if($_GET['post'] == $page_id){ add_post_type_support('page','excerpt'); } }
This code checks if the current page is the post edit screen for page with ID 123. If true, it adds support for excerpts.