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 :(
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 :(
Share Improve this question edited Mar 10, 2020 at 15:05 Tom J Nowell♦ 61.1k7 gold badges79 silver badges148 bronze badges asked Mar 10, 2020 at 14:39 Luke PalmerLuke Palmer 131 silver badge3 bronze badges 1 |3 Answers
Reset to default 1That 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.
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' ),
) );
}
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.
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