1

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 :(

1
  • It's possible that the problem is related to how and when you call add_theme_support, can you show the surrounding context for that function call? Is it inside another function? Which hook is it called on? Is it called on a hook?
    – Tom J Nowell
    Commented Mar 10, 2020 at 15:05

3 Answers 3

1

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.

1
  • Amazing! That did the trick, thank you!! Commented Mar 11, 2020 at 13:08
0

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' ),
    ) );
}
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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