11

Is there a way to add support for a custom feature for a custom post type, after it has been created?

I know how to create a custom post type using register_post_type(), and how to use the supports parameter to specify what the CPT should support;

'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt' ,'headway-seo') 

But for the situations when the CPT is being registered by a plugin or theme, is there a way to 'inject' support elements (manipulate the support array) of the CPT after it has been registered, using a WP hook/filter?

2
  • 2
    Just noticing that the answer is in the Codex page as well: register_post_type...
    – brasofilo
    Commented Oct 21, 2012 at 16:59
  • Just posted an alternative approach which may be useful in some specific cases.
    – Christine Cooper
    Commented Oct 19, 2017 at 10:33

2 Answers 2

14

Yes, there's a function called add_post_type_support

Hook into init -- late, after the post types have been created -- and add support.

Adding support for excerpts to pages for instance:

<?php
add_action('init', 'wpse70000_add_excerpt', 100);
function wpse70000_add_excerpt()
{
    add_post_type_support('page', 'excerpt');
}
4

An alternative approach is to hook into register_post_type_args and update the supports array.

This is particularly useful if you have third-party plugins that hook into the CPT arguments to display content.

function wpse70000_add_author_metabox_to_cpt_book( $args, $post_type ) {
    if ($post_type != 'POST_TYPE_NAME') // set post type
        return $args;
    $args['supports'] = array( 'author' ); // set the 'supports' array
    return $args;
}

add_filter( 'register_post_type_args', 'wpse70000_add_author_metabox_to_cpt_book', 10, 2 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.