add_theme_support('post-thumbnail') not working

I am new to Wordpress and following a training course. Its told me to enable to use of Featured Images I need to add the following line into my functions.php:

add_theme_support('post-thumbnails');

and then the following in my post types file:

    'supports' = array('title', 'editor', 'thumbnail'),

However I have done this but no luck getting the option to add a featured image. I have checked screen options and it is not appearing as an option I can enable.

I've checked similar threads already but no luck :(

Topic add-theme-support Wordpress

Category Web


You have right everything ok. Just you need to ensure that you have call the function inside init or after_setup_theme hook in the functions.php. It will look like the following codes-

function fn_name(){
 add_theme_support('post-thumbnails');
}
add_action('after_setup_theme','fn_name');

or

function fn_name(){
 add_theme_support('post-thumbnails');
}
add_action('init','fn_name');

and finally, ensure that thumbnail is supported in your CPT.


This is how it should look like in your theme's functions.php file:

<?php

/* Register thumbnail support */

add_action( 'after_setup_theme', 'my_theme_register_thumbnail_support' );
function my_theme_register_thumbnail_support() {
    add_theme_support( 'post-thumbnails' );
}

/* Register the custom post type */

add_action( 'init', 'my_theme_register_custom_post_type' );
function my_theme_register_custom_post_type() {
    register_post_type( 'my_post_type', array(
        'label'    => 'My Post Type',
        'supports' => array( 'title', 'editor', 'thumbnail' ),
    ) );
}

That one line is all you need, try adding this to your functions.php file.

function my_theme_setup(){
    add_theme_support('post-thumbnails');
}

add_action('after_setup_theme', 'my_theme_setup');

I'm not sure what your "post types file" is but the above should be enough to add support.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.