So I cant get the js for a lightbox plugin to work correctly. The error I get is:
Uncaught TypeError: undefined is not a function bootstrap-lightbox.js?ver=4.1:113
My functions.php:
function bootstrap_js() {
wp_enqueue_script( 'bootstrapjs', get_stylesheet_directory_uri() . '/js/bootstrap.js', array('jquery'), '', true );
wp_enqueue_script( 'bootstraplightbox', get_stylesheet_directory_uri() . '/js/bootstrap-lightbox.js', array('jquery'), '', true );
}
add_action( 'wp_enqueue_scripts', 'bootstrap_js');
And then I have this in my header.php
<?php wp_enqueue_script( 'jquery' ) ?>
I can find out whats wrong. I have been googling for hours now and none of the fixes I have found has worked for me (or understood them might be another reason).
I don't think you need the line to enqueue jQuery in your header, WordPress will handle that automagically as it is listed as a dependency of bootstrapjs. Additionally, you should probably list bootstrapjs as a dependency of bootstraplightbox like so:
wp_enqueue_script( 'bootstraplightbox', get_stylesheet_directory_uri() . '/js/bootstrap-lightbox.js', array('jquery', 'bootstrapjs'), '', true );
This will make sure that the bootstrapjs file is loaded before bootstraplightbox, as I am assuming that must happen.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.