WordPress Remove the query string from images

I’m optimizing my website and after some testing I found this:

Resources with a “?” in the URL are not cached by some proxy caching servers. Remove the query string and encode the parameters into the URL for the following resources:

Read More

I already fixed it for my JS and CSS files with this code:

function _remove_script_version( $src ){
    $parts = explode( '?ver', $src );
        return $parts[0];
}
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );

But for some reason almost all my images have Media Queries behind the extension too.

/wp-content/uploads/drupal-hosting-vergelijken.png?26f7af

/wp-content/plugins/custom-share-buttons-with-floating-sidebar/images/fb.png?26f7af

Is there a solution to prevent or remove this?

Related posts

1 comment

  1. If you are using W3 Total Cache, goto its Page Cache settings:
    From the WP left-hand menu, Click:
    Performance –> Browser Cache
    (— not the link at the top of the W3TC General Settings).
    Then UNCHECK:

    [] Prevent caching of objects after settings change
    Whenever settings are changed, a new query string will be generated and appended to objects allowing the new policy to be applied.

    This removed query strings from static Images on my website !!
    However, a few other js and css files with query strings still remain.

    I must try the solution provided above for the js and css files 🙂

    I found a plugin that removes js and css file queries.
    It’s code is that same as you provided above 🙂
    Yet may be more accessible for some:
    https://wordpress.org/plugins/remove-query-strings-from-static-resources/

Comments are closed.