Declaring script dependencies between scripts enqueued with different action hooks

The simple answer is, “No”. Although admin_enqueue_scripts and wp_enqueue_scripts hooks does exactly the same thing, the do their work in separate places which do not have any reference to the other.

  • wp_enqueue_scripts runs on the public side or front end

  • admin_enqueue_scripts As the name suggests, it runs on the admin side or back end

Your script that with the dependency will thus never load if it is depended on a script that is loaded via the other hook.

You will have to hook your bootstrap-js to both hooks for this to work, this will ensure that your dependency will work as well

Example:

add_action( 'wp_enqueue_scripts', 'enqueue_bootstrap_js' );
add_action( 'admin_enqueue_scripts', 'enqueue_bootstrap_js' );

function enqueue_bootstrap_js()
{
    //Register and enqueue your bootstrap-js script
}

add_action( 'wp_enqueue_scripts', 'tagsinput_scripts' );

function tagsinput_scripts()
{
    wp_enqueue_script('tagsinput-scripts', plugin_dir_url( __FILE__ ) . 'js/tagsinput/bootstrap-tagsinput.min.js', array('bootstrap-js'), '130215', false);
}

Leave a Comment