0

I've created a new post type gallery using CPT UI plugin, Now I want to add options to choose post Format and Featured Image in add new gallery post. Please check the attached screenshot. Could you please tell me how to get this option in add new post page.

enter image description here

1

First of all themes need to use add_theme_support() in the functions.php file to tell WordPress which post formats to support by passing an array of formats like so:

add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );

Note that you must call this before the init hook gets called! A good hook to use is the after_setup_theme hook.

Then by code you can add the post formats like below-

//add post-formats to post_type 'your_custom_post_type'
add_post_type_support( 'your_custom_post_type', 'post-formats' );

Also can add support on creation of post type like below-

// register custom post type 'your_custom_post_type' with 'supports' parameter
add_action( 'init', 'create_your_post_type' );
function create_my_post_type() {
    register_post_type( 'your_custom_post_type',
      array(
        'labels' => array( 'name' => __( 'Products' ) ),
        'public' => true,
        'supports' => array('title', 'editor', 'post-formats')
    )
  );
} 
  • Should I add this code in wp-admin/admin-functions.php ? – Suresh Alagar Nov 1 '16 at 10:34
  • Nope. Add those to your theme's functions.php file. – CodeMascot Nov 1 '16 at 10:35
  • Thank you its working :) How about Featured Image option in add new gallery post ? – Suresh Alagar Nov 1 '16 at 10:43
  • If this thing helped you will you please accept the answer. It would be very helpful. @SureshAlagar – CodeMascot Nov 1 '16 at 10:51
  • Please help. Check my answer below. I've created functions.php in my theme and added the code. But I am getting error message in my home page. – Suresh Alagar Nov 1 '16 at 11:00
0

When you will add new Custom Post Type using CPT UI plugin, you will see an option under Settings -> Support -> Post Formats in CPT UI Plugin.

enter image description here

  • Yes, choosen. Still it is not getting displayed in add new gallery post – Suresh Alagar Nov 1 '16 at 10:23
0

I've added the following code in funtions.php in my theme:

<?php

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

//add post-formats to post_type 'your_custom_post_type'
add_post_type_support( 'your_custom_post_type', 'post-formats' );

// register custom post type 'your_custom_post_type' with 'supports' parameter
add_action( 'init', 'create_your_post_type' );
function create_my_post_type() {
    register_post_type( 'your_custom_post_type',
      array(
        'labels' => array( 'name' => __( 'Products' ) ),
        'public' => true,
        'supports' => array('title', 'editor', 'post-formats')
    )
  );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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