Skip to content

Instantly share code, notes, and snippets.

@maddisondesigns
Last active May 7, 2021 16:34
Show Gist options
  • Save maddisondesigns/846091690f9b04b683417d249ffe3bd9 to your computer and use it in GitHub Desktop.
Save maddisondesigns/846091690f9b04b683417d249ffe3bd9 to your computer and use it in GitHub Desktop.
Update the version number on child theme stylesheet that's been enqueued from Parent theme
<?php
/**
* If you have a child theme that has had its stylesheet enqueued from within the main Parent theme,
* and you wish to update the version number that’s appended to the url, you can include this in your
* child theme functions.php file.
*
* Obviously, change the version number (‘6.0.0’ in this example) to whatever is appropriate for you,
* along with comparing the approriate stylesheet handle ('ephemeris-style' in this example)
*
* Where:
* $src – (string) The source URL of the enqueued style
* $handle – (string) The style's registered handle
*
*/
function mytheme_update_stylesheet_version( $src, $handle ) {
if( !strcmp( $handle, 'ephemeris-style' ) ) {
$src = get_stylesheet_uri();
$src = add_query_arg( 'ver', '6.0.0', $src );
}
return $src;
}
add_filter( 'style_loader_src', 'mytheme_update_stylesheet_version', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment