Child Theme Stylesheet Loading Before Parent Theme Stylesheet

I was using a child theme and following WordPress’s recommended way to load a parent’s stylesheet with wp_enqueue_style in the child theme functions.php file. However, the child theme stylesheet was loading before the parent theme stylesheet.

This was caused by a hard-coded reference to the stylesheet in the parent theme header.php file. I removed the hard-coded reference in the child theme header.php file and made the following modifications to my child theme wp_enqueue_style declarations:

add_action( 'wp_enqueue_scripts', 'my_enqueue_assets' );
function my_enqueue_assets() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
wp_register_style( 'child-style', get_stylesheet_directory_uri().'/style.css', array( 'parent-style' ) );
wp_enqueue_style( 'child-style' );
view raw gistfile1.txt hosted with ❤ by GitHub