How to enqueue style before style.css

Enqueue the style.css too, and set normalize as dependency:

if ( ! is_admin() )
{
    // Register early, so no on else can reserve that handle
    add_action( 'wp_loaded', function()
    {
        wp_register_style(
            'normalize',
            // parent theme
            get_template_directory_uri() . '/css/normalize.css'
        );
        wp_register_style(
            'theme_name',
            // current theme, might be the child theme
            get_stylesheet_uri(), [ 'normalize' ]
        );
    });
    add_action( 'wp_enqueue_scripts', function()
    {
        wp_enqueue_style( 'theme_name' );
    });
}

WordPress will load the dependencies now first automatically when theme_name is printed.

Leave a Comment