I’m creating a child theme (My first in over 3 years) of a WooCommerce theme and I’m having some trouble with the fact that some of the layout styles are enqueued in the parent theme and I’m having to add !important
to all the styles I want to override.
This is the current enqueue code in the parent themes functions.php;
if ( ! is_admin() ) { add_action( 'wp_enqueue_scripts', 'woo_load_frontend_css', 20 ); }
if ( ! function_exists( 'woo_load_frontend_css' ) ) {
function woo_load_frontend_css () {
wp_register_style( 'theme-stylesheet', get_stylesheet_uri() );
wp_register_style( 'woo-layout', get_template_directory_uri() . '/css/layout.css' );
wp_enqueue_style( 'theme-stylesheet' );
wp_enqueue_style( 'woo-layout' );
} // End woo_load_frontend_css()
}
What I need to do is load the child theme css AFTER the layout.css
file loaded by the parent theme.
I had the same problem and epilektric’s answer put me in the right path.
I am using “function” wootheme and it needs to load the parent style.css before another parent css called layout.css. So this order needs to be kept when loading the child theme’s style.css.
So basically, to avoid using
!important
to override all styles we need to load style files in the following order:To achieve that, we need to change:
Child theme’s style.css
Change this file to import both parent theme’s css files in the right order:
Child theme’s functions.php
Then add this to your functions.php to avoid re-loading layout.css (woo-layout) and to avoid loading child theme’s css (style.css):
You can also load an empty function like this to achieve the same effect:
Then register and add your child theme’s css by adding this to your child theme’s functions.php file right after the previous
function woo_load_frontend_css
:Now all stylesheet files will be loaded in the right order.
Because the Woo function is wrapped in
if( ! function_exists('function_name') )
you can override the function in your child theme’sfunctions.php
file.Add the function to the file and then adjust the queue order to load
style.css
afterlayout.css
.