This topic has 10 replies, 2 voices, and was last updated 7 years ago ago by Rose Tyler
tools like tools.pingdom.com suggest that i should remove query strings to increase site performance. i have installed “Remove Query Strings From Static Resources” plugin that solved some of the issue. How can i remove them all? I have found this code (have not tried yet) to be added to functions.php file:
function _remove_script_version( $src ){
$parts = explode( ‘?’, $src );
return $parts[0];
}
add_filter( ‘script_loader_src’, ‘_remove_script_version’, 15, 1 );
add_filter( ‘style_loader_src’, ‘_remove_script_version’, 15, 1 );
What do you suggest?
Hello,
Yes, you may try to use this code, add it in function.php file of your child theme.
Regards
HI,
I Got this error while trying to add the code via appereance-editor
Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. You will need to upload your PHP file change by some other means, such as by using SFTP.
Is there a way to update the code without SFTP?
Hello,
It is a bad practice to edit php files via Appearance > Editor, you need to connect and edit files via FTP. You may contact your hosting provider and ask credentials to FTP.
Regards
Thank you.
I have added mentioned code to functions.php via FTP resulting site crashing.
Alternatively tried following code resulting in no effect:
add_filter( ‘script_loader_src’, ‘wpse_216912_remove_query’ );
add_filter( ‘style_loader_src’, ‘wpse_216912_remove_query’ );
function wpse_216912_remove_query( $src ) { // Remove query strings from static resources also jetpack query
if ( strpos( $src, ‘?ver=’ ) || strpos( $src, ‘&ver=’ ) || strpos( $src, ‘?w=’) || strpos( $src, ‘?a600e5’) ) {
$src = remove_query_arg( array( ‘ver’, ‘w’, ‘a600e5’ ), $src );
}
return $src;
}
It is strange, did you add the code in functions.php file of child theme? Is the child theme activated on your site?
Yes, you may use this code:
add_filter( 'script_loader_src', 'wpse_216912_remove_query' );
add_filter( 'style_loader_src', 'wpse_216912_remove_query' );
function wpse_216912_remove_query( $src ) { // Remove query strings from static resources also jetpack query
if ( strpos( $src, '?ver=' ) || strpos( $src, '&ver=' ) || strpos( $src, '?w=') || strpos( $src, '?a600e5') ) {
$src = remove_query_arg( array( 'ver', 'w', 'a600e5' ), $src );
}
return $src;
}
I’ve added the code on my test site and it works fine http://prntscr.com/hmypu1
Also, you need to optimize images http://prntscr.com/hmyqfo
https://www.elegantthemes.com/blog/tips-tricks/optimize-images-for-your-wordpress-website
Use special services or WordPress plugins to optimize your images for decreased loading times:
– tinypng.com
– Compressor.io
– Kraken.io
– Ewww Image Optimizer
– Smush Image Compression and Optimization plugin
Regards
Thank you for pointing me to image optimization.
The code has still no effect. I have attached a screenshot.
Did you add the code via FTP? Is child theme activated on your site?
Regards
Yes to both questions. It seems that the code is actually working but not for the facebook page widget. Would the solution be to remove the widget and add the facebook plugin manually via javascript? How to do that? Thank you.
Hello,
Sorry but these resources https://prnt.sc/hnhkoc do not relate to our theme.
In case you need professional help with site optimization you may contact wpkraken team because that is outside the scope of our support.
Regards
You must be logged in to reply to this topic.Log in/Sign up