WordPress – adding Featured image to custom Post Type

I’m trying to add a Featured Image to my theme but not for Posts or Pages – I’ve created a custom type called Properties (its for an estate agent), so how do I enable Featured Image, as it doesn’t appear in the sceen options?

Hope someone can help,

$property  = new Cuztom_Post_Type( 'Property', array(
    'supports' => array('title', 'editor')
));

Related posts

Leave a Reply

7 comments

  1. $property  = new Cuztom_Post_Type( 'Property', array(
        'supports' => array('title', 'editor', 'thumbnail')
    ));
    

    I appear to have solved my own question – see above

  2. This might help someone,

    add_theme_support('post-thumbnails');
    add_post_type_support( 'my_product', 'thumbnail' );    
    function create_post_type() {
            register_post_type( 'my_product',
                array(
                    'labels' => array(
                        'name' => __( 'Products' ),
                        'singular_name' => __( 'Product' )
                    ),
                    'public' => true,
                    'has_archive' => true
                )
            );
        }
        add_action( 'init', 'create_post_type' );
    
  3. You can simply enable support Post thumbnail for any custom post type with the following line of code in the theme’s function.php file.

    add_post_type_support( 'forum', 'thumbnail' );
    

    Note: Here, the forum is the post type name.

    You can keep this code in the after_setup_theme hook.

  4. Probably this would help

        function create_post_type() {
      register_post_type( 'sadaf_films',
        array(
          'labels' => array(
            'name' => __( 'Films' ),
            'singular_name' => __( 'Film' )
          ),
          'public' => true,
          'has_archive' => true,
          'supports' => array( 'title', 'editor', 'custom-fields','thumbnail' ),
        )
      );
    }
    add_action( 'init', 'create_post_type' );
    
  5. 100% working this code

     add_theme_support('post-thumbnails');
    add_post_type_support( 'news', 'thumbnail' ); 
    
    function create_posttype() {
        register_post_type( 'news',
            array(
                'labels' => array(
                    'name' => __( 'News' ),
                    'singular_name' => __( 'news' )
                ),
                'public' => true,
                'has_archive' => true,
                'rewrite' => array('slug' => 'news'),
                'menu_icon' => 'dashicons-format-aside',
    
            )
        );
    }
    add_action( 'init', 'create_posttype' );
    
  6.     add_theme_support('post-thumbnails');
        add_post_type_support( 'testimonial', 'thumbnail' );
    
        function create_posttype() {
         register_post_type( 'testimonial',
            array(
                    'labels' => array(
                        'name' => __( 'Testimonial' ),
                        'singular_name' => __( 'testimonial' )
                    ),
                    'public' => true,
                    'has_archive' => true,
                    'rewrite' => array('slug' => 'testimonial'),
                    // add category in custom post type
                    'taxonomies' => array( 'category'),
                )
            );
        }
    
        add_action( 'init', 'create_posttype' );
    
  7. If you use wp cli and scaffold for creating your custom post-type:

    wp scaffold post-type movie ...

    You will find that your generated file (/post-type/movie.php) already has the line, in register_post_type:

    supports: => ['title', 'editor' ]

    And there you can add ‘thumbnail’:

    supports: => ['title', 'editor', 'thumbnail' ]