0
votes

I have a theme and a child theme and I am trying to load child theme blank css files to override the parent theme files rules.

In parent theme,, there is a style.css in theme root dir and there is responsive.css in /assets/css/ directory

In child theme there is style.css and responsive.css in child root directory

the functions.php has this code in it but the only thing that works is if I apply !important to child style css rules.

add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );

function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/assets/css/responsive.css' );
    wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/responsive.css' );

}

How can I get my custom files to load AFTER the them main css files?

1

1 Answers

2
votes

You can determine the load order by declaring dependencies. Note that all handles must be unique:

add_action( 'wp_enqueue_scripts', 'so27575579_enqueue_styles' );
function so27575579_enqueue_styles()
{
    wp_register_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_register_style( 'parent-style-resp', get_template_directory_uri() . '/assets/css/responsive.css', array( 'parent-style' ) );
    wp_register_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( 'parent-style-resp' ) );
    wp_register_style( 'child-style-resp', get_stylesheet_directory_uri() . '/responsive.css', array( 'child-style' ) );

    wp_enqueue_style( 'child-style-resp' );
}