Search
Close this search box.

How to remove query variables / version numbers from style or script in WordPress

To remove query variables or version numbers from styles or scripts in WordPress, you can use the style_loader_src and script_loader_src filters in your theme’s functions.php file. These filters allow you to modify the URLs of styles and scripts that are enqueued in WordPress.

Here’s an example of how you can use these filters to remove query variables or version numbers from styles or scripts:

// Remove query variables / version numbers from style or script
// More snippets at wpunplugged.com 

add_filter( 'style_loader_src', 'remove_query_vars_version', 10, 2 );
function remove_query_vars_version( $src, $handle ) {
    return remove_query_arg( 'ver', $src );
}

add_filter( 'script_loader_src', 'remove_query_vars_version', 10, 2 );
function remove_query_vars_version( $src, $handle ) {
    return remove_query_arg( 'ver', $src );
}

This code will remove any query variables named “ver” from the URLs of styles and scripts. If you want to remove other query variables or version numbers, you can modify the code to use a different name or pattern.

Keep in mind that removing query variables or version numbers from styles and scripts may not always be necessary or desirable. For example, some themes or plugins may rely on these variables to load specific versions of styles or scripts, or to prevent caching issues. If you are unsure whether you should remove these variables from your site, you may want to consult the theme or plugin documentation or reach out to the developer for guidance.

Share this post

You might also like...

Best WordPress hosting
Articles & How-to

Best WordPress hosting

WordPress hosting is becoming increasingly popular as a reliable and affordable way to host websites. The best WordPress hosting providers offer powerful features, reliable uptime,

Read More »

Comment

Your email address will not be published. Required fields are marked *