showing results for - "defer parsing of javascript wordpress"
Yannick
26 Jan 2018
1// Only for Javascript
2
3function defer_parsing_of_js( $url ) {
4    if ( is_user_logged_in() ) return $url; //don't break WP Admin
5    if ( FALSE === strpos( $url, '.js' ) ) return $url;
6    if ( strpos( $url, 'jquery.js' ) ) return $url;
7    return str_replace( ' src', ' defer src', $url );
8}
9add_filter( 'script_loader_tag', 'defer_parsing_of_js', 10 );