How to remove WordPress version parameter from JAVASCRIPT and CSS files

How to remove WordPress version parameter from JAVASCRIPT and CSS files

Sometimes we strongly need to remove WordPress Version Parameter from javascript. In WordPress files, there are Many JAVASCRIPT and CSS files that have the WordPress version number appended to their URL. In this post, I will show how we can remove the version number from JS and CSS URL in WordPress.

We can use 2 methods.

  1. Remove the “ver” parameter from all wordpress enqueued CSS and JAVASCRIPT files
  2. Remove only the “ver” parameter only if its value matches the WordPress version number from all wordpress enqueued CSS and JS files

Method 1: Remove the “ver” parameter from all wordpress enqueued CSS and JAVASCRIPT files

Just add the code of the below methods in your theme’s functions.php file.

/ remove wordpress version param from any enqueued scripts
    function wcb_remove_wp_ver_css_js( $src ) {
        if ( strpos( $src, 'ver=' ) )
            $src = remove_query_arg( 'ver', $src );
        return $src;
    }
    add_filter( 'style_loader_src', 'wcb_remove_wp_ver_css_js', 9999 );
    add_filter( 'script_loader_src', 'wcb_remove_wp_ver_css_js', 9999 );

Method 2: Remove only the “ver” parameter only if its value matches the WordPress version number from all wordpress enqueued CSS and JS files

Just add the code of the below methods in your theme’s functions.php file.

// remove wordpress version param from any enqueued scripts
    function wcb_remove_wp_ver_css_js( $src ) {
        if ( strpos( $src, 'ver=' . get_bloginfo( 'version' ) ) )
            $src = remove_query_arg( 'ver', $src );
        return $src;
    }
    add_filter( 'style_loader_src', 'wcb_remove_wp_ver_css_js', 9999 );
    add_filter( 'script_loader_src', 'wcb_remove_wp_ver_css_js', 9999 );