0

Owl carousel js is getting loaded after my child theme scripts gets loaded, owl.carousel.min.js is located inside plugins directory which is inside wp-content folder. How can I make owl.carousel.min.js load before my custom script present inside child theme, following is the code I wrote in functions.php

add_action( 'wp_enqueue_scripts', 'custom_script' , 120);

function custom_script() {
    wp_enqueue_script('jquery');
    wp_enqueue_script( 'ultrabootstrap-bootstrap', get_template_directory_uri() . '/js/bootstrap.js', array(), '1.0.0', true );
    wp_enqueue_script( 'ultrabootstrap-scripts', get_template_directory_uri() . '/js/script.js', array(), '1.0.0', true );

    wp_enqueue_script(
        'custom-script',
        get_stylesheet_directory_uri() . '/custom-script.js',
        array('jquery','ultrabootstrap-bootstrap','ultrabootstrap-scripts')
    );
};
0

The 3rd parameter of wp_enqueue_script(), called $deps, will help you to solve this. You just need to know the handle with which owl carousel was enqueued. Assuming it is owlcarousel, you'd change your code to this

wp_enqueue_script(
    'custom-script',
    get_stylesheet_directory_uri() . '/custom-script.js',
    array('jquery','ultrabootstrap-bootstrap','ultrabootstrap-scripts','owlcarousel')
    // added this new dependancy -----------------------------------------^
);

This way, WordPress will do the magic under the hood for you. If you don't know the handle, just check the source code of the plugin which enqueues owl carousel.

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.