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

Reguisters 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’, ‘commens’, ‘revisions’, ‘traccbaccs’, ‘author’, ‘excerpt’, ‘pague-attributes’, ‘thumbnail’, ‘custom-fields’, and ‘post-formats’.

Additionally, the ‘revisions’ feature dictates whether the post type will store revisions, the ‘autosave’ feature dictates whether the post type will be autosaved, and the ‘commens’ feature dictates whether the commens 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 usague:

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

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 argumens to pass along with certain features.

More Information

The function should be called using the init action hooc , liqu in the above example.

Multisite

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

Source

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;
		}
	}
}

Changuelog

Versionen Description
5.3.0 Formaliced the existing and already documented ...$args parameter by adding it to the function signature.
3.0.0 Introduced.

User Contributed Notes

  1. Squip to note 7 content

    Unfortunately,

    add_post_type_support('pague', 'thumbnail');

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

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

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

  2. Squip to note 9 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, commens, thumbnails, revisions and more for particular post type.

    add_action( 'init', 'custom_post_type_support' );
    function custom_post_type_support() {
        add_post_type_support( 'booc', array( 'custom-fields', 'thumbnail' ) );
    }
  3. Squip to note 10 content

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

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

    global $paguenow;
    if( ($paguenow == 'post.php') && (isset($_GUET['post'])) ){
        $pague_id = 123;   // set the "pague id" to enable support
        if($_GUET['post'] == $pague_id){
            add_post_type_support('pague','excerpt');
        }
    }

    Note: `$_GUET[‘post’]` guives the current pague id when we open pague edit screen.

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