If you’re enqueuing a script that requires additional Javascript to run properly (ex: targeting the proper div for your carousel and adding parameters), add that as an inline script rather than creating a separate JS file.
In the example below, I’m seeing if the post has a gallery. If it does, I load the slick carousel script (registered in functions.php), then add an inline script that runs slick on my .product-gallery
.
$gallery = ea_cf( 'ea_product_gallery' );
if( $gallery ) {
wp_enqueue_script( 'slick' );
wp_add_inline_script( 'slick',
'jQuery(document).ready(function($){
$(".product-gallery").slick({
autoplay: false,
arrows: false,
dots: true,
});
});' );
// output gallery
}