add generated stylesheet from parent theme after child-themes style.css

Absolutely!

Into functions.php, like you said. I’ll call it cache_busting_styles because I like how it sounds.

First, you set up the style via wp_enqueue_style, then call it during the action hook wp_print_styles, Also, you’ll want to set up a variable and pass it in there as the version number as well:

function cache_busting_styles() {
    //however you set up your version number here
    $version = 'cachebustingversion';
    wp_enqueue_style('cachebusting', get_bloginfo('template_url').'/parent-theme/generated.css', '', $version, 'screen');
}
add_action('wp_print_styles', 'cache_busting_styles');

wp_enqueue_style accepts 5 arguments, first the handle, an ID wordpress associates with the stylesheet (must be unique), second the URL of the file, third the other files it depends on (any required files that should be loaded along with this file, I left it null, you may add anything you want, it uses other enqueued stylesheets handles), fourth the version, which it adds to the end of the link URL just like what you are looking for (You may pass whatever you want into this, WordPress puts it’s current version in here by default), and finally the media argument for the CSS file (screen, print, all, etc…) I hope this helps!

Edit: Just wanted to make clear that using this method should always add this sheet after the default style-sheet, but to make very sure, add_action accepts a third argument which is the priority of the action. A very large number will guarantee it running last, but something like 8 or 12 should do the trick, just in case you need to force the order.

add_action('wp_print_styles', 'cache_busting_styles', 12);

Leave a Comment