skip to Main Content

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.

  1. I disabled all plugins
  2. I changed the theme (and the featured image appears in wp-admin normally)
  3. I removed all code from functions, leaving only the code above
  4. 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


  1. Anything that is declared inside the function.php file need to be hooked onto a action/filter.

    <?php
    
    /**
     * Registers theme support for a given feature.
     * 
     * @link https://developer.wordpress.org/reference/functions/add_theme_support/
     */
    add_action( 'init', 'theme_support' );
    
    if ( ! function_exists( 'theme_support' ) ) {
    
        function theme_support () {
    
            /**
             * This feature enables Post Thumbnails support for a theme. Note that you can optionally pass a second argument, $args, with an array of the Post Types for which you want to enable this feature.
             * 
             * @link https://developer.wordpress.org/reference/functions/add_theme_support/#post-thumbnails
             */
            add_theme_support( 'post-thumbnails' );
    
        };
    
    };
    

    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 a support argument array.

    // ...
    'supports' => array( 'title', 'editor', 'thumbnail', ) // Default is an array containing 'title' and 'editor'.
    
    Argument Description
    supports (array) Core feature(s) the post type supports. Serves as an alias for calling add_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‘.
    Login or Signup to reply.
  2. You could hook it to after_setup_theme action hook. So, the code would be something like this:

    add_action('after_setup_theme', 'your_theme_features');
    
    function your_theme_features()
    {
      add_theme_support('post-thumbnails');
      set_post_thumbnail_size( 1280, 720 );
    };
    

    "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 use set_post_thumbnail_size function too.

    Login or Signup to reply.
  3. 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

    index.php
    The main template file. It is required in all themes.

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search