Skip to content

Snippet: Add Version Number To Your Child Theme Script Query Parameter

If you find that the browser is caching your child theme so people don't see your live edits you can add some code to your child theme to add the version number from your child theme to the script query parameters which lets the browser know the correct version to cache.

function total_child_requeue_child_style() {

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

    // Get version number
    $theme   = wp_get_theme();
    $version = $theme->get( 'Version' );

    // Re-add child theme with currect version number
    wp_enqueue_style( WPEX_THEME_STYLE_HANDLE, get_stylesheet_uri(), array(), $version );

}
add_action( 'wp_enqueue_scripts', 'total_child_requeue_child_style' );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top