Craig
Craig

Reputation: 1962

How can I get my Child Theme's Stylesheet to load after Parent Theme's 'Colour Theme' Stylesheets?

I have created a Child Theme, whereby I have enqueued the stylesheets as follows:

<?php
function child_theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'custom_css', get_template_directory_uri() . '/css/custom-stylesheet.css', array(), '1.0', 'all' );
}
add_action( 'wp_enqueue_scripts', 'child_theme_enqueue_styles', 10 );
?>

The above code, ensures that the Child Theme Custom Stylesheet loads after the Parent Theme Stylesheets. That said, the Parent Theme also has the following CSS Files within the following directories, which load after the Child Theme Stylesheets:

<link rel='stylesheet' id='responsive-css'  href='http://www.example.com/wp-content/themes/theme/assets/css/responsive.css?ver=4.7.3' type='text/css' media='all' />
<link rel='stylesheet' id='theme-skin-color8-css'  href='http://www.example.com/wp-content/themes/theme/assets/css/theme-skin/color8.css?ver=4.7.3' 

I have checked the priority settings for the above files and none have been set. I have also changed the priorities of the Child Theme stylesheets, yet this has no affect.

Does anyone have any other possible suggestions, that I can try, in order to ensure that the Child Theme Stylesheet loads last?

Upvotes: 0

Views: 1228

Answers (1)

I&#39;m Joe Too
I&#39;m Joe Too

Reputation: 5840

If no priority has been set on the wp_enqueue_scripts function calling those other stylesheets, then their priority is at 10 and setting your call to a higher priority will work:

function child_theme_enqueue_styles() {
  wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
  wp_enqueue_style( 'custom_css', get_template_directory_uri() . '/css/custom-stylesheet.css', array(), '1.0', 'all' );
}
add_action( 'wp_enqueue_scripts', 'child_theme_enqueue_styles', 11 );

If this isn't working, then the parent theme is poorly coded and not properly enqueuing those other stylesheets.

Upvotes: 2

Related Questions