Remove Version Query Variable for CSS and JS Files

WordPress adds by default a version query variable to CSS and JS files. An example would look like: style.css?ver=1.2.3.

If you want to avoid that (e.g. for using Chrome Dev Tools, otherwise you can’t map the files to local files), use the snippet below.

function wpkb_remove_cssjs_ver( $src ) {
    if ( strpos( $src, '?ver=' ) ) {
        $src = remove_query_arg( 'ver', $src );
    }

    return $src;
}

add_filter( 'style_loader_src', 'wpkb_remove_cssjs_ver', 10, 2 );
add_filter( 'script_loader_src', 'wpkb_remove_cssjs_ver', 10, 2 );

If you want to disable the query vars only when using the WordPress debug mode, you can modify the snippet above:

if ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ) {
    function wpkb_remove_cssjs_ver( $src ) {
        if ( strpos( $src, '?ver=' ) ) {
            $src = remove_query_arg( 'ver', $src );
        }

        return $src;
    }

    add_filter( 'style_loader_src', 'wpkb_remove_cssjs_ver', 10, 2 );
    add_filter( 'script_loader_src', 'wpkb_remove_cssjs_ver', 10, 2 );
}