Archived topic
Generate styles overriding my child theme styles
7 replies · Started by Anonymous on December 12, 2015
Hello,
I've created a child theme of Generate. The only content in style.css is info about my child theme. In functions.php I've added this code:
function rbt_styles() {
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/main.css'
);
}
add_action( 'wp_enqueue_scripts', 'rbt_styles' );
This loads my main.css file, but the default Generate stylesheet is overriding all my child theme styles. I thought WordPress loaded the parent theme's styles before the child theme's? I understand Generate sees I'm using a child theme and loads its own styles automatically?
Do I need to load my child theme styles differently?
Thanks,
Leon
You actually don't need to enqueue your stylesheet - GeneratePress does it for you.
Here's a blank child theme: http://generatepress.com/api/themes/generatepress_child.zip
Thanks Tom,
That's helpful. However, I'm using SASS to build my child theme stylesheet, so ideally I'd like to not use style.css at all. I think the 'proper' way to load an additional stylesheet (main.css in my case) is to enqueue it?
I guess I could output my SASS file to style.css, complete with the opening child theme comments? I'm not sure that would work if I compress the CSS.
If I did this and still wanted to add stylesheets afterwards, will Generate allow this? Does it load additional stylesheets after the parent theme's?
L
Gotcha! In that case, just add a later priority to your add_action call:
add_action( 'wp_enqueue_scripts', 'rbt_styles', 500 );
That will make your stylesheet show up after the others.
Thanks Tom, that's great. Should've RTFM more closely :-)
Thanks for your time. Really liking the theme: good typographic defaults, neutral and configurable enough to build stuff on.
L
Glad I could help! Thanks for using GP :)
Thanks for this, I was wondering the same thing, because I'd like to pull the CSS tweaks out of the customizer and into a Sass'ified child theme as well.
Glad it was helpful to you as well :)