1

I'm just moving a theme from Vercel that done in HTML/CSS/Bootstrap/Nuxt.js to be deployed in WordPress trying to enqueue the css files and js but doesn't load at all the content of front-page.php and the header.php get displayed but without styling just dummy html and the path seem pretty correct if I open the files of the theme itself in the browser it's rendering normally.

    if (!function_exists('setup_robertson_theme')) :
        /**
         * Sets up theme defaults and registers support for various
         * WordPress features.
         *
         * Note that this function is hooked into the after_setup_theme
         * hook, which runs before the init hook. The init hook is too late
         * for some features, such as indicating support post thumbnails.
         */
        function setup_robertson_theme()
        {
            add_action('wp_enqueue_scripts', 'add_theme_scripts');
            wp_enqueue_style('style', get_stylesheet_uri());
    
            /**
             * Make theme available for translation.
             * Translations can be placed in the /languages/ directory.
             */
            load_theme_textdomain('robertson_theme', get_template_directory() . '/languages');
    
            /**
             * Add default posts and comments RSS feed links to <head>.
    
    
             */
            add_theme_support('automatic-feed-links');
    
            /**
             * Enable support for post thumbnails and featured images.
             */
            add_theme_support('post-thumbnails');
    
            /**
             * Add support for two custom navigation menus.
             */
            register_nav_menus(array(
                'primary' => __('Primary Menu', '   robertson_theme'),
                'secondary' => __('Secondary Menu', 'myfirsttheme'),
            ));
    
            /**
             * Enable support for the following post formats:
             * aside, gallery, quote, image, and video
             */
            add_theme_support('post-formats', array('aside', 'gallery', 'quote', 'image', 'video'));
    
    
    
            get_header();
        }
    endif; // setup_robertson_theme
    add_action('after_setup_theme', 'setup_robertson_theme');



function add_theme_scripts()
{
    wp_enqueue_style('style', get_stylesheet_uri());
    wp_enqueue_style('style2', get_theme_file_uri() . '/style.css');

    wp_enqueue_script('script1', get_template_directory_uri() . '/_nuxt/default.9609efb5.js', array('jquery'), 1.1, true);
    wp_enqueue_script('script2', get_template_directory_uri() . '/_nuxt/entry.fe69eefa.js', array('jquery'), 1.1, true);
    wp_enqueue_script('script3', get_template_directory_uri() . '/_nuxt/nuxt-link.bd1ab28f.js', array('jquery'), 1.1, true);


    // if (is_singular() && comments_open() && get_option('thread_comments')) {
    //     wp_enqueue_script('comment-reply');
    // }
}
add_action('wp_enqueue_scripts', 'add_theme_scripts');

1 Answer 1

1

You use get_header() in the after_setup_theme.

The get_header() function should be used only in theme template files, not directly in the after_setup_theme hook.

Does the theme work now?

4
  • note that get_header shouldn't be used that early, it should only be called from theme template files Commented Jul 5, 2023 at 18:58
  • Who was that meant for? Commented Jul 5, 2023 at 19:04
  • it was to add context to why using get_header on the after_setup_theme hook doesn't work and suggest a better place to put it. Note that the answer was auto-flagged by internal tooling for being very short, you should edit your answer so it's longer and to avoid back and forth. I upvoted it as it identifies the crux of the problem but it doesn't say where to move get_header to to fix the problem Commented Jul 5, 2023 at 20:52
  • 1
    @tom-j-nowell Thanks, the answer is now longer and also has a more detailed explanation. Commented Jul 6, 2023 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.