Remove Query Strings from Static Resources

1. Remove Query Strings from Static Resources with Code

You can easily remove query strings from your assets with a few lines of code. Simply add the following to your WordPress theme’s functions.php file.

function remove_query_strings() {
   if(!is_admin()) {
       add_filter('script_loader_src', 'remove_query_strings_split', 15);
       add_filter('style_loader_src', 'remove_query_strings_split', 15);
   }
}

function remove_query_strings_split($src){
   $output = preg_split("/(&ver|\?ver)/", $src);
   return $output[0];
}
add_action('init', 'remove_query_strings');

Important: Editing the source code of a WordPress theme could break your site if not done correctly. If you aren’t comfortable doing this, please check with a developer first

  • WordPress Optimization
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Categories and tags have vanished

The problem ended up being that system alerts had caused certain functions to shut down. One of...

Leverage Browser Caching

<IfModule mod_expires.c> ExpiresActive On ExpiresDefault "access plus 1 month"...

How to deactivate all plugins when not able to access the administrative menus?

Sometimes it may be necessary to deactivate all plugins, but you can't access the administrative...

How to Move a WordPress Website from HTTP to HTTPS/SSL

Configuring WordPress for SSL/HTTPS Links in WordPress (such as image attachments, themes CSS...

WordPress Security - Base64 and eval

WordFence has a scanner that can find base64 and eval code. You can use CPANEL file manager to...