Remove Query String From CSS & Javascript In WP

To see your website Top in Google search result it is required that your site well developed and according to google standard. Site loading time is the most important factor to get good position in Google and other search engine result.

Today, Gtmetrix, Pingdom, Google page speed insight tool etc Many online tools available on web to check site designed or not according to SEO standard.

According to Pingdom & Gtmetrix tool suggestion removing query strings from static resources like css style sheet and java-script url is the higher priority which is considered during the speed test of website which contain query sting in css and javascript file.



Why used query string in CSS JS Url?

Query string with version in url is a method followed by Developer to instantly render new updates and carry the different plugins version details with file. Normally Query string are used for both java-script and style-sheets file calling url.

Why need to remove query string From CSS JS url

As per Pingdom tools suggestion " 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:"
Some Proxy server not cache the url which has Query string hence to get good speed performance for website it better to store static CSS, Js files store in Browser cache and render quickly on user second visit.

Remove query string from static resources in Wordpress

There are 2 easy method in Wordpress to remove Query String from Static CSS, Javascript file.

# 1 Add Few line code in Wordpress theme function.php file

Very basic Programming Skill required to add following code in current theme function.php file. You can either choose to edit your theme via wordpress dashboard or use ftp software or online file manager from your hosting cpanel.
// Remove query string from static files 

function remove_css_js_ver( $src ) 
{
   if( strpos( $src, '?ver' ) ) 
   {
    $rqs = explode( '?ver', $src );
    return $rqs[0];
   }
   if( strpos( $src, '?rev' ) ) 
   {
       $rqs = explode( '?rev', $src );
       return $rqs[0];
   }
   return $src;
}

add_filter( 'style_loader_src', 'remove_css_js_ver', 15, 2 );
add_filter( 'script_loader_src', 'remove_css_js_ver', 15, 2 ); 


# 2 Use WP Plugin Remove query strings from static Resources

It is very easiest way to deal with Query sting in Wordpress. no need to edit any file or no need back up of Live Database just add and activate remove query strings from static resources plugin.

Still If you have any query or facing problem kindly share in comment.
ion

Post a Comment

0 Comments