Menu Close

How to remove the WordPress version from some css and js files?

Codeamend
Code Snippet to remove the CSS and JS file version to improve the site speed.
add_filter( 'style_loader_src',  'cmd_remove_ver_css_js', 9999, 2 );
add_filter( 'script_loader_src', 'cmd_remove_ver_css_js', 9999, 2 );

function cmd_remove_ver_css_js( $src, $handle ) 
{
    $handles_with_version = [ 'style' ];

    if ( strpos( $src, 'ver=' ) && ! in_array( $handle, $handles_with_version, true ) )
        $src = remove_query_arg( 'ver', $src );

    return $src;
} 
Posted in WordPress

You can also read...