0

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';
webdev1995
  • 33
  • 3

1 Answers1

0

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.

Elvin Haci
  • 3,108
  • 1
  • 14
  • 20
  • I replace the line above but I get an error because the class has a private constructor. It's strange that this class is giving me issued because my styles are enqueued in a class that works in the theme. :( – webdev1995 Feb 20 '21 at 20:20
  • Yes, you can remove private from there if it is not needed. or you can use get_instanse method given in this answer: https://stackoverflow.com/a/12553217/701666 – Elvin Haci Feb 20 '21 at 21:45
  • The featured image section still isn't showing up :( – webdev1995 Feb 20 '21 at 21:53
  • I don't see whole structure there, but if you can't solve it, then why not to use add_theme_support( 'post-thumbnails' ); in your functions.php ? Just paste that single line there and that's all. – Elvin Haci Feb 20 '21 at 21:54
  • I put this in the functions.php: `function wcs_setup() { add_theme_support( 'post-thumbnails' ); } add_action( 'after_theme_setup', 'wcs_setup' );` But it still isn't showing up. Any advice? – webdev1995 Feb 20 '21 at 21:59
  • that should be after_setup_theme, not after_theme_setup – Elvin Haci Feb 20 '21 at 22:00