Skip to main content
Beautifying code
Source Link
Doug
  • 139
  • 1
  • 8

As per WP Code Snippet blog, it looks like this is one way:

Add this code snippet to your functions.php file.

// add async and defer to javascripts

function wcs_defer_javascripts ( $url ) 
{
if ( FALSE === if (strpos( $url, '.js' ) === FALSE) { 
        return $url;
    }
    if ( strpos( $url, 'jquery.js' ) ) { 
        return $url;
    }
    return "$url' async onload='myinit()";
}
add_filter( 'clean_url', 'wcs_defer_javascripts', 11, 1 );

As per WP Code Snippet blog, it looks like this is one way:

Add this code snippet to your functions.php file.

// add async and defer to javascripts

function wcs_defer_javascripts ( $url ) 
{
if ( FALSE === strpos( $url, '.js' ) ) return $url;
    if ( strpos( $url, 'jquery.js' ) ) return $url;
    return "$url' async onload='myinit()";
}
add_filter( 'clean_url', 'wcs_defer_javascripts', 11, 1 );

As per WP Code Snippet blog, it looks like this is one way:

Add this code snippet to your functions.php file.

// add async and defer to javascripts

function wcs_defer_javascripts ($url) 
{
    if (strpos($url, '.js') === FALSE) { 
        return $url;
    }
    if (strpos($url, 'jquery.js')) { 
        return $url;
    }
    return "$url' async onload='myinit()";
}
add_filter('clean_url', 'wcs_defer_javascripts', 11, 1);
Source Link
Doug
  • 139
  • 1
  • 8

As per WP Code Snippet blog, it looks like this is one way:

Add this code snippet to your functions.php file.

// add async and defer to javascripts

function wcs_defer_javascripts ( $url ) 
{
if ( FALSE === strpos( $url, '.js' ) ) return $url;
    if ( strpos( $url, 'jquery.js' ) ) return $url;
    return "$url' async onload='myinit()";
}
add_filter( 'clean_url', 'wcs_defer_javascripts', 11, 1 );