Parent stylesheet loading after child
-
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.
- The topic ‘Parent stylesheet loading after child’ is closed to new replies.