add_post_type_support( string $post_type, string|array $feature, mixed $args )

Registers support of certain features for a post type.


Description

All core features are directly associated with a functional area of the edit screen, such as the editor or a meta box. Features include: ‘title’, ‘editor’, ‘comments’, ‘revisions’, ‘trackbacks’, ‘author’, ‘excerpt’, ‘page-attributes’, ‘thumbnail’, ‘custom-fields’, and ‘post-formats’.

Additionally, the ‘revisions’ feature dictates whether the post type will store revisions, and the ‘comments’ feature dictates whether the comments count will show on the edit screen.

A third, optional parameter can also be passed along with a feature to provide additional information about supporting that feature.

Example usage:

add_post_type_support( 'my_post_type', 'comments' );
add_post_type_support( 'my_post_type', array(
    'author', 'excerpt',
) );
add_post_type_support( 'my_post_type', 'my_feature', array(
    'field' => 'value',
) );

Top ↑

Parameters

$post_type string Required
The post type for which to add the feature.
$feature string|array Required
The feature being added, accepts an array of feature strings or a single string.
$args mixed Optional
Optional extra arguments to pass along with certain features.

Top ↑

More Information

The function should be called using the init action hook, like in the above example.  

Top ↑

Multisite

To show the “Featured Image” meta box in mulsite installation, make sure you update the allowed upload file types, in Network Admin, Network Admin Settings SubPanel#Upload_Settings, Media upload buttons options. Default is off.

Top ↑

Source

File: wp-includes/post.php. View all references

function add_post_type_support( $post_type, $feature, ...$args ) {
	global $_wp_post_type_features;

	$features = (array) $feature;
	foreach ( $features as $feature ) {
		if ( $args ) {
			$_wp_post_type_features[ $post_type ][ $feature ] = $args;
		} else {
			$_wp_post_type_features[ $post_type ][ $feature ] = true;
		}
	}
}


Top ↑

Changelog

Changelog
Version Description
5.3.0 Formalized the existing and already documented ...$args parameter by adding it to the function signature.
3.0.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 2 content
    Contributed by Marc Heatley

    Unfortunately,

    add_post_type_support('page', 'thumbnail');

    won’t add featured images to pages. For that you need to [add theme support for post-thumbnails

    add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );

    https://developer.wordpress.org/reference/functions/add_theme_support/#post-thumbnails

  2. Skip to note 4 content

    The example that allows you to add support for specific feature to a custom post type. It’s used to enable or disable certain features, Such as custom fields, excerpts, comments, thumbnails, revisions and more for particular post type.

    add_action( 'init', 'custom_post_type_support' );
    function custom_post_type_support() {
        add_post_type_support( 'book', array( 'custom-fields', 'thumbnail' ) );
    }
  3. Skip to note 5 content
    Contributed by Irfan

    To enable `add_post_type_support` for a specific page or post, we can narrow down with condition.

    Example: To add support for excerpt in page (id : 123), use this:

    global $pagenow;
    if( ($pagenow == 'post.php') && (isset($_GET['post'])) ){
        $page_id = 123;   // set the "page id" to enable support
        if($_GET['post'] == $page_id){
            add_post_type_support('page','excerpt');
        }
    }

    Note: `$_GET[‘post’]` gives the current page id when we open page edit screen.

You must log in before being able to contribute a note or feedback.