Last active
October 18, 2019 08:37
-
-
Save tux255/54929d4577742b362e6f60140c611893 to your computer and use it in GitHub Desktop.
Loadspeed theme improvements for Wordpress -> functions.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Remove query strings from urls | |
function remove_query_strings( $src ) { | |
$src = remove_query_arg( array( 'v', 'ver', 'rev', 'bg_color', 'sensor' ), $src ); | |
return $src; | |
} | |
add_filter( 'style_loader_src', 'remove_query_strings', 10, 2 ); | |
add_filter( 'script_loader_src', 'remove_query_strings', 10, 2 ); | |
// Defer parsing of JavaScripts | |
function defer_parsing_js( $url ) { | |
if ( ! is_admin() ) { | |
if ( false === strpos( $url, '.js' ) ) { | |
return $url; | |
} | |
if ( strpos( $url, 'jquery.js' ) ) { | |
return $url; | |
} | |
if ( strpos( $url, 'slick.min.js' ) ) { | |
return $url; | |
} | |
if ( strpos( $url, 'custom.js' ) ) { | |
return $url; | |
} | |
if ( strpos( $url, 'functions.min.js' ) ) { | |
return $url; | |
} | |
if ( strpos( $url, 'jquery.bxslider.min.js' ) ) { | |
return $url; | |
} | |
return "$url' defer='defer"; | |
} else { | |
return $url; | |
} | |
} | |
add_filter( 'clean_url', 'defer_parsing_js', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment