questions

Add theme support for post thumbnail isn’t working from theme class

Rate this post

I have a theme class that I bootstrap my theme in and add the theme support but the featured image meta box isn’t appearing.

Inside the class file:

class WCS_THEME{

    private function __construct() {
        $this->setup_hooks();
    }

    // Singleton design code here

    protected function setup_hooks() {
        add_action( 'after_theme_setup', [ $this, 'setup_theme' ] );
    }

    public function setup_theme() {
        add_theme_support( 'post-thumbnails' );
    }
}
\WCS_THEME\Inc\WCS_THEME::get_instance();

Inside functions.php:

require WCS_DIR_PATH . '/inc/classes/class-wcs-theme.php';

 

✔️Solution:

First of all, simply replace

\WCS_THEME\Inc\WCS_THEME::get_instance();

with

$instance=new \WCS_THEME\Inc\WCS_THEME();

Also, it is a bit strange that you don’t get fatal error with the code above. Turn debugging to TRUE to see PHP warnings.

I believe there is some problem with WCS_DIR_PATH. Print full path with

echo WCS_DIR_PATH . '/inc/classes/class-wcs-theme.php';

to make sure it is a correct path to your file.

Leave a Reply

Your email address will not be published.

Back to top button