2

My parent theme's style.css has a dependency on bootstrap.css, which is also part of the parent theme.

From parent themes functions.php:

wp_enqueue_style('bootstrap', get_template_directory_uri().'/css/bootstrap.min.css);
wp_enqueue_style('style', get_stylesheet_uri(), array('bootstrap'));

When using a child theme the parents style.css gets loaded first, despite it having a dependency on bootstrap.

My child's style enqueuing function looks like this:

function child_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css', 'parent-bootstrap');
}

And even when setting a dependency when enqueuing the parent style, it seems to be ignored and the style.css is loaded before bootstrap

function child_enqueue_styles() {
    wp_enqueue_style( 'parent-bootstrap', get_template_directory_uri().'/css/bootstrap.min.css');
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css', 'parent-bootstrap');
}

I'm not sure how to deal with this without altering the parent theme

2

I'm sure you missed it but the dependency parameter should be an array and not a string.

So your enqueue function should be:

function child_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css', array('bootstrap'));
}

or:

function child_enqueue_styles() {
    wp_enqueue_style( 'parent-bootstrap', get_template_directory_uri().'/css/bootstrap.min.css');
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css', array('parent-bootstrap'));
}

Reference: wp_enqueue_style

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.