0

As soon as I add the $deps array to my wp_enqueue_script, the script is 'enqueued', but not 'done'. Any ideas?

function bootstrap_script_init() {
    wp_register_script('bootstrap', get_template_directory_uri(). '/js/bootstrap.min.js', array('jquery'), '3.3.7', true);
    wp_enqueue_script('bootstrap');
}
add_action( 'wp_enqueue_scripts', 'bootstrap_script_init' );
  • Where are you including this code? And what do you mean by 'done'? Printed? – ssnepenthe Oct 6 '17 at 16:39
  • @ssnepenthe exactly, it doesn't get printed – Kode Bryant Oct 6 '17 at 19:11
0

You could run a couple checks and enqueue jquery if it's not registered or enqueued using wp_script_is

function bootstrap_script_init() {

    // Check to see if jQuery is registered, if not, register it.
    // You can use the local version of WP's jQuery if you want instead of Google's API.
    if ( !wp_script_is( 'jquery', 'registered' ) ){
        wp_register_script( 'jquery', '//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array(), '3.2.1', true );
    }

    // Check to see if it is enqueued, if not, enqueue it.
    if ( !wp_script_is( 'jquery', 'enqueued' ) ){
        wp_enqueue_script( 'jquery' );
    }

    wp_register_script('bootstrap', get_template_directory_uri(). '/js/bootstrap.min.js', array('jquery'), '3.3.7', true);
    wp_enqueue_script('bootstrap');
}
add_action( 'wp_enqueue_scripts', 'bootstrap_script_init' );
  • jQuery should always be registered by default so I would say this is unnecessary... If it has gone missing you have a plugin or theme doing something that it probably shouldn't be doing. Also there is no need to manually enqueue it - adding jquery as a dependency should ensure that it is automatically enqueued. – ssnepenthe Oct 6 '17 at 16:38
  • that's the odd thing. The $deps script are printed, but no the 'bootstrap' script – Kode Bryant Oct 6 '17 at 19:12

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.