Skip to main content

I have two render blocking JS from wordpress core. jquery.js and jquery-migrate.min.js. Following this answer on WPSE I was able to add `defer="defer"' to the script tag that calls for jquery-migrate and bootstrap, but doing the same for 'jquery' does not add the defer property to the script tag that calls for jquery.js

  add_filter( 'script_loader_tag', function ( $tag, $handle ) {
    $handlesToDefer = array('jquery-migrate', 'bootstrap', 'jquery');

    if ( !in_array($handle, $handlesToDefer) )
        return $tag;

    return str_replace( ' src', ' defer="defer" src', $tag );
 }, 1, 2 );

}, 1, 2 );

jquery defer bootstrap defer

I have two render blocking JS from wordpress core. jquery.js and jquery-migrate.min.js. Following this answer on WPSE I was able to add `defer="defer"' to the script tag that calls for jquery-migrate and bootstrap, but doing the same for 'jquery' does not add the defer property to the script tag that calls for jquery.js

add_filter( 'script_loader_tag', function ( $tag, $handle ) {
$handlesToDefer = array('jquery-migrate', 'bootstrap', 'jquery');

if ( !in_array($handle, $handlesToDefer) )
    return $tag;

return str_replace( ' src', ' defer="defer" src', $tag );

}, 1, 2 );

jquery defer bootstrap defer

I have two render blocking JS from wordpress core. jquery.js and jquery-migrate.min.js. Following this answer on WPSE I was able to add `defer="defer"' to the script tag that calls for jquery-migrate and bootstrap, but doing the same for 'jquery' does not add the defer property to the script tag that calls for jquery.js

  add_filter( 'script_loader_tag', function ( $tag, $handle ) {
    $handlesToDefer = array('jquery-migrate', 'bootstrap', 'jquery');

    if ( !in_array($handle, $handlesToDefer) )
        return $tag;

    return str_replace( ' src', ' defer="defer" src', $tag );
 }, 1, 2 );

jquery defer bootstrap defer

Source Link

Unable to defer loading of jquery

I have two render blocking JS from wordpress core. jquery.js and jquery-migrate.min.js. Following this answer on WPSE I was able to add `defer="defer"' to the script tag that calls for jquery-migrate and bootstrap, but doing the same for 'jquery' does not add the defer property to the script tag that calls for jquery.js

add_filter( 'script_loader_tag', function ( $tag, $handle ) {
$handlesToDefer = array('jquery-migrate', 'bootstrap', 'jquery');

if ( !in_array($handle, $handlesToDefer) )
    return $tag;

return str_replace( ' src', ' defer="defer" src', $tag );

}, 1, 2 );

jquery defer bootstrap defer