0

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

0
add_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 );
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.