I'd like to use WordPress with Bootstrap but WordPress does not load jQuery properly so I get this error message:
Uncaught TypeError: Bootstrap's JavaScript requires jQuery. jQuery must be included before Bootstrap's JavaScript.
This is from my functions.php:
function add_theme_scripts() {
wp_enqueue_style('bootstrap', 'https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css');
wp_enqueue_style('style', get_theme_file_path() . '/style.css');
wp_enqueue_script('jquery');
wp_enqueue_script('Popper', 'https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js', array('jquery'), null, true);
wp_enqueue_script('Bootstrap', 'https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js', array('jquery', "Popper"), null, true);
wp_enqueue_script('script', get_theme_file_path() . '/assets/js/script.js', array('jquery', 'Popper', 'Bootstrap'), null, true);
}
add_action('wp_enqueue_scripts', 'add_theme_scripts');
Could you please help me with this issue? Thanks a lot in advance
jQuery
in the dev console and pressing enter. if it returnedundefined
then it isn't loaded. You can also look at the source code to check if jQuery's JS file is present, and the network tab. Don't rely on bootstrap to check, it may be incorrect