How to remove query strings - by omthreetimes

This topic has 10 replies, 2 voices, and was last updated 6 years, 11 months ago ago by Rose Tyler

  • Avatar: omthreetimes
    omthreetimes
    Participant
    December 13, 2017 at 13:20

    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?

    Please, contact administrator
    for this information.
    9 Answers
    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    December 13, 2017 at 13:47

    Hello,

    Yes, you may try to use this code, add it in function.php file of your child theme.

    Regards

    Avatar: omthreetimes
    omthreetimes
    Participant
    December 13, 2017 at 13:57

    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?

    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    December 13, 2017 at 14:03

    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

    Avatar: omthreetimes
    omthreetimes
    Participant
    December 13, 2017 at 14:39

    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;
    }

    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    December 13, 2017 at 15:08

    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

    Avatar: omthreetimes
    omthreetimes
    Participant
    December 13, 2017 at 15:36

    Thank you for pointing me to image optimization.

    The code has still no effect. I have attached a screenshot.

    Please, contact administrator
    for this information.
    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    December 13, 2017 at 16:03

    Did you add the code via FTP? Is child theme activated on your site?

    Regards

    Avatar: omthreetimes
    omthreetimes
    Participant
    December 14, 2017 at 16:30

    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.

    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    December 14, 2017 at 17:08

    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

  • Viewing 10 results - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.Log in/Sign up

8theme customization service
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.