Remove query strings from WordPress assets to allow caching.

When you’re trying to squeeze every available bit of performance from your website, you’ve no doubt looked into caching.

When caching, most assets with a query string are not cached, so this will hamper your efforts and decrease performance.

What is a query string? A query string is the ?something= parameter in the URL.

WordPress automatically adds version query strings to your CSS & JS assets when they are loaded.

If you look at your website source, you’ll see something like <link rel="stylesheet" src="" type="text/css" media="all" />.

Notice the ?ver=123, that’s the query string blocking your caching.

How do we do it?

Removing is relatively easy, let’s take a look. Simply add the following function to your functions.php file.

if ( ! function_exists( 'uncoverwp_remove_query_strings' ) ) :
     * Remove query strings from
     * assets for caching
    function uncoverwp_remove_query_strings( $src )
        return remove_query_arg( 'ver', $src );
    add_filter( 'script_loader_src', 'uncoverwp_remove_query_strings' );
    add_filter( 'style_loader_src', 'uncoverwp_remove_query_strings' );

This simply adds our function to remove the query argument on the script and style loader tags, thus removing the query string from the assets URLs.


A very easy way to boost your sites performance and allow full caching of assets.


Want us to email you occasionally with our latest courses, news & updates?

We use cookies to ensure that we give you the best possible experience on our website. If you continue to use this site we will assume that you are happy with it. OK Privacy Policy