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 );
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 );
Share Improve this question edited Sep 30, 2019 at 14:13 Chetan Vaghela 2,4084 gold badges10 silver badges16 bronze badges asked Sep 30, 2019 at 13:42 OctaviaLoOctaviaLo 1398 bronze badges
1 Answer
Reset to default 0add_filter( 'script_loader_tag', function ( $tag, $handle ) {
$handlesToDefer = array('jquery-migrate', 'bootstrap', 'jquery-core');
if ( !in_array($handle, $handlesToDefer) )
return $tag;
return str_replace( ' src', ' defer="defer" src', $tag );