Remove query strings from static resources

Posted in: Newspaper
Post count: 76

There were errors showing in Pingdom ‘Remove query strings from static resources”

The way I removed this was to go to the theme’s functions.php and add the code just below the <?php (line 2)

This is what I added and the errors are now gone!

function _remove_script_version( $src ){
$parts = explode( ‘?ver’, $src );
return $parts[0];
}
add_filter( ‘script_loader_src’, ‘_remove_script_version’, 15, 1 );
add_filter( ‘style_loader_src’, ‘_remove_script_version’, 15, 1 );

Just thought it would be nice to share. Now my Pingdom Perf Grade has gone up to 94/100

  • This topic was modified 12 years by ToniLaird.
Post count: 56

Thanks for sharing, but it gives me the error … let’s see that theme developers say

Post count: 9544

Just for reference, the code I posted in the PageSpeed sticky topic – which can be added to bottom of functions.php file. Your mileage may vary 🙂

function remove_cssjs_ver( $src ) {
    if( strpos( $src, '?ver=' ) )
        $src = remove_query_arg( 'ver', $src );
    return $src;
}
add_filter( 'style_loader_src', 'remove_cssjs_ver', 10, 2 );
add_filter( 'script_loader_src', 'remove_cssjs_ver', 10, 2 );
  • This reply was modified 12 years by simchris.
Post count: 76

Hi Christopher,
Is this different to the code I already added and for a difference purpose?

Thanks

Toni

Viewing 4 posts - 1 through 4 (of 4 total)
The forum ‘Newspaper’ is closed to new topics and replies.