1

I have a script being auto created in wp-includes/script-loader.php

This is jquery that wordpress depends on as well as some plugins for the site

$scripts->add( 'jquery-core', '/wp-includes/js/jquery/jquery.js', array(), '1.12.4' );

I need to add defer to the tag where this is created, I tried removing it and moving to the head but wordpress as well as the dependent plugins break as if its totally missing.

I assume its code like this, just not sure which to change:

$src = $wp_scripts->base_url . "/wp-admin/load-scripts.php?c={$zip}&" . $concat . '&ver=' . $wp_scripts->default_version;
        echo "<script type='text/javascript' src='" . esc_attr($src) . "'></script>\n";

Any ideas. Thanks.

2
  • Check this out, which explains how to add defer attribute. Commented Aug 7, 2017 at 15:40
  • So where would that script_loader_tag code go? Commented Aug 7, 2017 at 15:42

1 Answer 1

0
add_filter( 'script_loader_tag', function ( $tag, $handle ) {

    if ( 'jquery-core' !== $handle )
        return $tag;

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

Provided by: toscho

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.