defer parsing of javascript wordpress without plugin code example
Example 1: defer parsing of javascript wordpress
function defer_parsing_of_js( $url ) {
if ( is_user_logged_in() ) return $url;
if ( FALSE === strpos( $url, '.js' ) ) return $url;
if ( strpos( $url, 'jquery.js' ) ) return $url;
return str_replace( ' src', ' defer src', $url );
}
add_filter( 'script_loader_tag', 'defer_parsing_of_js', 10 );
Example 2: defer parsing of javascript avada
function defer_parsing_of_js( $url ) {
if ( is_user_logged_in() ) return $url;
if ( FALSE === strpos( $url, '.js' ) ) return $url;
if ( strpos( $url, 'jquery.js' ) ) return $url;
return str_replace( ' src', ' defer src', $url );
}
add_filter( 'script_loader_tag', 'defer_parsing_of_js', 10 );