• Resolved eSaner

    (@esaner)


    Just a note to other’s that might run into this problem:

    I’m using WP-Forge as a parent theme with a customized version of WP-Starter as a child theme. After recently updating WP-Forge I noticed that its stylesheet was loading after the child theme’s stylesheet.

    I’m enqueueing the parent theme in functions.php of the child theme as described here: https://codex.www.ads-software.com/Child_Themes. If I also enqueue the child theme stylesheet as a dependency of the parent theme, the child theme stylesheet is loaded twice, once before the parent theme’s and once after.

    I traced this to line 212 of functions.php in WP-Forge, where the wpforge_scripts() function calls get_stylesheet_uri(). When a child theme is used, get_stylesheet_uri() will point to the child theme’s stylesheet, instead of the parent theme’s stylesheet. This function is loaded at priority 0, so if you use the function from the WP codex that only enqueues the parent theme as is (without specifying a priority), the default priority of 10 causes the parent theme’s stylesheet to load after the child’s stylesheet.

    This is solved by adding a priority of 0 to the function in the child theme’s functions.php that enqueues that parent theme’s styles (child functions.php is loaded before parent). The odd thing about this solution is that when the child theme stylesheet is loaded in the <head>, it’s listed with id=”wpforge-css”, even though it’s not from that theme. There’s also a version number appended to the url that is inaccurate.

    Perhaps there’s a better way to fix this, but that was the best I could come up with.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Theme Author ThemeAWESOME

    (@tsquez)

    Hey there,

    Glad you are using WP-Forge as well as WP-Starter.

    In regards to WP-Starter, I believe the version of WP-Starter you are using may be old. Version 3.0 uses the following:

    /**
     * Enqueue our child-theme style sheets
     */
    function wpstarter_child_style() {
        wp_dequeue_style('wpforge');
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css', '', '3.0' );
        wp_enqueue_style( 'child-style', get_stylesheet_uri(), array( 'parent-style' ), '3.0' );
    }
    add_action( 'wp_enqueue_scripts', 'wpstarter_child_style');

    You can even see this on the Github repo: https://github.com/tsquez/wp-starter/blob/master/functions.php

    A user came up with the idea of doing it this way and it has been in place for a while, 3 months as a matter of fact. Also no priority is needed. Works like a charm. If you like you can see it by viewing the page source of ThemeAwesome.

    Again thank you for using WP-Forge as well as WP-Starter. If you can please leave a review. Enjoy!

    Thread Starter eSaner

    (@esaner)

    That’s a nicer solution. Thanks!

    Theme Author ThemeAWESOME

    (@tsquez)

    Very welcome.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Parent stylesheet loading after child’ is closed to new replies.