0

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 Answer 1

2

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' );
}
Sign up to request clarification or add additional context in comments.

4 Comments

I don't get it (I mean I get your answer but i don't get the problem).. My child style.css overrides parent style.css but my responsive parent.css overrides child responsive.css
My responsive.css apparently gets cued in inc/scripts.php on this line wp_enqueue_style( 'theworld-responsive', trailingslashit( get_template_directory_uri() ) . 'assets/css/responsive.css' );
If that responsive stylesheet is enqueued separately, without any relation to the parent's style.css, you could dequeue it first.
I think I found it.. there is a misfiring logic with enqueuing the responsive in the main template,, I will dequeue it and use mine instead. Thanks for the help! Your solution works a charm when main template is logically set.

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.