Skip to content

Instantly share code, notes, and snippets.

@ethanpil
Created July 9, 2015 21:25
Show Gist options
  • Save ethanpil/5d86a50d3cf44989a035 to your computer and use it in GitHub Desktop.
Save ethanpil/5d86a50d3cf44989a035 to your computer and use it in GitHub Desktop.
Ensure child theme's style.css is loaded after all parent theme's css, including layout.css (For woothemes products)
<?php
/*
The best solution to make sure that your child theme's style.css loads after the parent theme's layout.css.
Then you can easily override the small things you need in the usual manner via style.css and upgrade the
parent theme without worry Here is some code that works for WooThemes products, which ensures that your
child theme css is always loaded after the parent child's layout.css
It belongs in the child theme's functions.php
*/
function use_parent_theme_stylesheet() {
// Use the parent theme's stylesheet
return get_template_directory_uri() . '/style.css';
}
function my_theme_styles() {
$themeVersion = wp_get_theme()->get('Version');
// Enqueue our style.css with our own version
wp_enqueue_style('child-theme-style', get_stylesheet_directory_uri() . '/style.css',
array('woo-layout'), $themeVersion);
}
// Filter get_stylesheet_uri() to return the parent theme's stylesheet
add_filter('stylesheet_uri', 'use_parent_theme_stylesheet');
// Enqueue this theme's scripts and styles (after parent theme)
add_action('wp_enqueue_scripts', 'my_theme_styles', 20);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment