1

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';

1 Answer 1

1

If that's the whole class then you don't have a method called get_instance

By the way, even if you had a get_instance method, you are calling get_instance as a static method, __construct gets called only when creating a new instance from the class using the new keyword, like this

$obj = new WCS_THEME();

That's basically it, Going the your class in it's current state, all you need to do is a new instance, as shown in the code above.

Don't forget about the namespace we creating the instance

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.