Search code examples
phpwordpresscustom-post-typepost-format

Enable "Post Formats" Just For a "Custom Post Type" And Not Others In WordPress


I've been struggling with Post Formats and CPTs in WordPress and after many hours, I decided to create some CPTs and enable Post Formats for them.

The problem is, when I enable Post Formats, they become available for all of the post types; and I want to have them just for some of the CPTs and not other ones.

Assume I have three CPTs called "article", "webinar" and "tutorial" . I want to enable Post Formats just for "webinar".

What I've done is to create a plugin and enable Post Formats with:

add_theme_support( 'post-formats', array( 'audio', 'image', 'video', 'gallery' ));

after that, I tried to enable them for CPT which is called medya:

add_post_type_support( 'medya', 'post-formats');

and then, I tried to disable them for defalut "post" post type.

remove_theme_support( 'post', 'post-formats');

But it doesn't work and Post Formats are enabled for both. Any suggestions?


Solution

  • Answered

    I found the answer here.

    function remove_pf() {
        remove_meta_box( 'formatdiv','post','normal' );
    }
    add_action( 'admin_menu', 'remove_pf' );