I configured functions.php with the code that enables Post Thumbnails on the theme, but it doesn’t appear in wp-admin.
<?php
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 1280, 720 );
When I create a post, the option to upload the featured image does not appear. So, I did the following procedures to try to understand what is going on.
- I disabled all plugins
- I changed the theme (and the featured image appears in wp-admin normally)
- I removed all code from functions, leaving only the code above
- I updated WordPress
I don’t know what to do anymore, I researched a lot and I can’t find a solution. Could anyone have mercy on my soul? Thanks!!!
3
Answers
Anything that is declared inside the
function.php
file need to be hooked onto a action/filter.Custom post type case
If you’re talking about custom post type, when you register a new one via
register_post_type()
you can specify asupport
argument array.supports
array
) Core feature(s) the post type supports. Serves as an alias for callingadd_post_type_support()
directly. Core features include ‘title
‘, ‘editor
‘, ‘comments
‘, ‘revisions
‘, ‘trackbacks
‘, ‘author
‘, ‘excerpt
‘, ‘page-attributes
‘, ‘thumbnail
‘, ‘custom-fields
‘, and ‘post-formats
‘. Additionally, the ‘revisions’ feature dictates whether the post type will store revisions, and the ‘comments’ feature dictates whether the comments count will show on the edit screen. A feature can also be specified as an array of arguments to provide additional information about supporting that feature. Example:array( 'my_feature', array( 'field' => 'value' ) )
. Default is an array containing ‘title
‘ and ‘editor
‘.You could hook it to
after_setup_theme
action hook. So, the code would be something like this:"Copy/paste" the code in your
functions.php
. The "the featured image" section should show up for your posts. Also you should be able to useset_post_thumbnail_size
function too.Feb 2022
WordPress version 5.9.1
It’s been 9 months and I hope OP found the solution.
If anyone came to this post asking for the same question then try this.
Here’s what the Official Theme Handbook says
Solution
Make sure your theme has an
index.php
file.It doesn’t matter it has content or is empty, but the file has to exist.
Thanks to @teshn for finding this.