Cyber Week Sale! Get $20 off GP Premium, $40 off our new Lifetime license, and 45% off license renewals/extensions! Learn more

[Resolved] Generate styles overriding my child theme styles

Home Forums Support Generate styles overriding my child theme styles

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #159589
    Leon

    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

    #159608
    Tom
    Lead Developer
    Lead Developer

    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

    #159630
    Leon

    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

    #159631
    Tom
    Lead Developer
    Lead Developer

    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.

    #159638
    Leon

    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

    #159642
    Tom
    Lead Developer
    Lead Developer

    Glad I could help! Thanks for using GP 🙂

    #307965
    James

    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.

    #308020
    Tom
    Lead Developer
    Lead Developer

    Glad it was helpful to you as well 🙂

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.