Snippets: Add Version Number to Child Theme to Prevent Browser Cache

This code would be added in your child theme's functions.php and what it does is re-registeres the child theme with the current style.css version number so whenever you make changes to your child theme you can update your version number and it will update the ?v= parameter in the style.css URL to prevent browser caching.

add_action( 'wp_enqueue_scripts', function() {

	// Make sure WPEX_THEME_STYLE_HANDLE is defined
	if ( ! defined( 'WPEX_THEME_STYLE_HANDLE' ) ) {

	// First de-register the main child theme stylesheet
	wp_deregister_style( WPEX_THEME_STYLE_HANDLE );

	// Then add it again, using the version number from the child theme
	$theme   = wp_get_theme();
	$version = $theme->get( 'Version' );
	wp_register_style( WPEX_THEME_STYLE_HANDLE, get_stylesheet_uri(), array(), $version );

	// Finally enqueue it again
	wp_enqueue_style( WPEX_THEME_STYLE_HANDLE );

} );
All PHP snippets should be added via a child theme's functions.php file.