🎉 Happy 4th of July! Get 15% off GP Premium with the discount code: 4THOFJULY2020

[Resolved] Enqueue style.css sheet generated from .scss within child theme

Home Forums Support Enqueue style.css sheet generated from .scss within child theme

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1125014
    Heather

    Hi,

    I have the GP child theme so that I can have custom stylesheets and functions.php sheets, and I am using .scss for my styles. My preprocessor creates a minified style.css sheet from the style.scss, but it does not seem to be registering.

    The location of the new style.css sheet is generatepress_child folder > styles > style.css

    I tried to enqueue it with a folder path in the get_stylesheet_directory_uri() but it did not work. Any suggestions for the code to use in my functions.php, or should I have the style.css file generated outside of that styles folder?

    It seems like it keeps trying to look for the style.css sheet that comes with the child theme as I keep getting this error:
    Warning: filemtime(): stat failed for …./wp-content/themes/generatepress_child/style.css

    But I obviously want to remove this stylesheet and only pull from my new one in my styles folder.

    Thanks

    #1125080
    Leo
    Staff
    Customer Support
    #1125854
    Heather

    Hi,

    This does not unfortunately. I already know that WordPress or any browser doesn’t read .scss files. I am already running a preprocessor and have a new style.css file that has been generated from the style.scss file. The problem is that I can’t seem to enqueue that new .css file, so I want to know what exactly I should put into my functions.php file in order to have this .css file loading.

    I know I have to “register” it, but no code I am putting in is working. I am not sure if it is because the .css file is located a new folder called “styles” that is inside the child theme folder, but something isn’t catching.

    Could you help me with this code? Just need to enqueue that new file instead of the theme defaulting to the style.css file that comes with the child theme.

    #1126266
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Try this:

    add_action( 'wp_enqueue_scripts', function() {
        wp_enqueue_style( 'your-handle', get_stylesheet_directory_uri() . "/styles/style.css", array(), filemtime( get_stylesheet_directory() . "/styles/style.css" ) );
    } );

    Let me know 🙂

    #1126894
    Heather

    That worked better! I didn’t have that filemtime part. However, I am still getting this warning at the top of my page:

    Warning: filemtime(): stat failed for …/wp-content/themes/generatepress_child/style.css in …/wp-content/themes/generatepress/inc/general.php on line 35

    So it seems like it’s still trying to load the style.css sheet that comes with the child theme. Do I have to change something in that general.php sheet?

    This is what is on that line:
    `if ( is_child_theme() ) {
    wp_enqueue_style( ‘generate-child’, get_stylesheet_uri(), array( ‘generate-style’ ), filemtime( get_stylesheet_directory() . ‘/style.css’ ), ‘all’ );
    }`

    Do I just need to update that to the /styles/style.css?

    #1126973
    Tom
    Lead Developer
    Lead Developer

    Ah, you can just dequeue that stylesheet:

    add_action( 'wp_enqueue_scripts', function() {
        wp_dequeue_style( 'generate-child' );
        wp_enqueue_style( 'your-handle', get_stylesheet_directory_uri() . "/styles/style.css", array(), filemtime( get_stylesheet_directory() . "/styles/style.css" ) );
    }, 50 );
    #1127957
    Heather

    Unfortunately it is still giving me the same warning. I tried changing the ‘generate-child’ to ‘style.css’ but that did not work either.

    Other suggestions? Change the code on that line directly? try a different target to dequeue?

    #1127959
    Heather

    Actually nevermind, I think it is fine – I literally removed the style.css sheet from the generate-child theme folder and it caused the warning to come up, but when I added it back and inspected my styles I can see that they are loading from the styles/style.css

    So I think it is working as intended?

    #1128024
    Tom
    Lead Developer
    Lead Developer

    Yep, that should work fine – having the file there should prevent the warning, and the code above should make sure it doesn’t actually load on your website.

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