Wordpress - adding Featured image to custom Post Type
Asked Answered
A

7

20

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')
));
Argument answered 22/9, 2012 at 12:4 Comment(0)
A
28
$property  = new Cuztom_Post_Type( 'Property', array(
    'supports' => array('title', 'editor', 'thumbnail')
));

I appear to have solved my own question - see above

Argument answered 22/9, 2012 at 15:36 Comment(1)
I like your approach with creating content type - Can you provide link to its documentation? So far I could not find it in docs.Miru
C
10

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' );
Chery answered 8/12, 2015 at 9:57 Comment(0)
S
9

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.

Sneakers answered 25/6, 2020 at 20:32 Comment(0)
J
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' );
Janice answered 28/3, 2019 at 11:55 Comment(0)
S
3

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' );
Syne answered 15/7, 2018 at 11:1 Comment(0)
G
1

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' ]

Gerald answered 21/11, 2022 at 21:33 Comment(0)
S
0
    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' );
Sudan answered 25/4, 2019 at 12:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.