add_post_type_support() wordpress function and usage This text is not used because the data attribute has a value

add_post_type_support() wordpress function and usage

Home / WordPress / WordPress Wiki / add_post_type_support() wordpress function and usage

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',
) );

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) extra arguments to pass along with certain features.

More Information

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

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.

Sample Usage

For an overview of all possible features (e.g. ‘title’, ‘editor’, etc.), see the documentation for post_type_supports.

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' ) );

add_theme_support()

This example adds support for excerpts in pages (assuming it is *not* showing under “Screen Options”):

<?php
add_action('init', 'wpdocs_custom_init');
 
/**
 * Add excerpt support to pages
 */
function wpdocs_custom_init() {
    add_post_type_support( 'page', 'excerpt' );
}
?>

 

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments