How to Remove Query Strings From Static Resources Without a Plugin

WpFASTER Code 4 Comments

As a general performance rule, the less plugins you use the better. So, use this code snippet to remove query strings from static resources instead.

To do so, copy and paste this code snippet — in plain text — to your functions.php file, or, add it with a plugin like Code Snippets.

function remove_cssjs_ver( $src ) {
 if( strpos( $src, '?ver=' ) )
 $src = remove_query_arg( 'ver', $src );
 return $src;
}
add_filter( 'style_loader_src', 'remove_cssjs_ver', 10, 2 );
add_filter( 'script_loader_src', 'remove_cssjs_ver', 10, 2 );

Comments 4

    1. Hi DeDoHo,

      I was running into this problem as well. First I tried changing the ‘ver’ to ‘v’ in both locations in the script. Unfortunately that didn’t work. So I resorted to diving into the code and manually taking out the version information from the font-awesome.min.css file.

      I’ve tested this out and I haven’t had any issues so far. Note: this obviously won’t work if you’re using one of the cdns to get the font-awesome files.

      I’m going to do a YouTube demonstration on how to do this. You can check out my channel and see some WordPress Tutorials. https://www.youtube.com/c/Pixemweb

  1. Hey I found you comment on here, im having the same issue with font awesome.
    I couldn’t find the video on your youtube page, although I will follow as you have some great stuff.

    Any help appreciated 🙂

Leave a Reply

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