1

I have this type of query string, Like:

https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js?ba0a5a&ba0a5a https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js?ba0a5a&ba0a5a https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css?ba0a5a&ba0a5a

How to remove, for example, ?ba0a5a&ba0a5a, from the URL.

  • 2
    These don't look "normal" and WP doesn't natively load jQuery from a CDN. I would recommend to determine where are they coming from and why do they get queries attached first. – Rarst Sep 11 '18 at 16:41
2

You can remove the Query Strings using this code in your functions.php

function _remove_query_strings( $src ){ 
    $parts = explode( '?', $src );  
    return $parts[0]; 
} 
add_filter( 'script_loader_src', '_remove_query_strings', 15, 1 ); 
add_filter( 'style_loader_src', '_remove_query_strings', 15, 1 ); //not need to in your case since it's for the CSS files
  • 2
    While this answers question literally, I highly recommend to never do this unconditionally for all scripts/styles. It's very normal for WP core and extensions to use query strings for versioning of assets (which is suboptimal technique from cache perspective, but it is what it is). – Rarst Sep 11 '18 at 16:43
  • Use it "at your own risk" I should've added. Thanks. – Castiblanco Sep 11 '18 at 16:45
  • Yeah, wouldn't this break cache-revving via url params? I think OP should find where those scripts are enqued and remove the query-strings manually. do a global search in the theme for enqueue_script &/or the urls that have query-strings added to them & see if there's a simpler (more concise less global) solution (like just removing the query strings or adding an exception to the filter which is adding them in the first place). – admcfajn Sep 11 '18 at 17:05
  • This function removes only ?v,?var type query string but not remove ?ba0a5a&ba0a5a this type query string. This function not working. – Rakesh Patidar Sep 12 '18 at 4:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.