Here’s a tweaked version of the original code. get_template_directory_uri()
is used instead of hard coding the URLs, the scripts and styles are enqueud rather than just being registered, and the dependencies are specified.
<?php
function wptuts_scripts_load_cdn() {
wp_enqueue_script( 'multi-select', get_template_directory_uri() . '/selector/js/jquery.multi-select.js', array( 'jquery' ), null, false );
// JavaScript for theme. Presumably where you'd want to initialize the multi-select element.
//wp_enqueue_script( 'theme-scripts', get_template_directory_uri() . '/js/theme-scripts.js', array( 'jquery', 'multi-select' ), null, false );
wp_enqueue_script( 'bs4', 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/js/bootstrap.min.js', array(), null, false );
}
add_action( 'wp_enqueue_scripts', 'wptuts_scripts_load_cdn' );
function wptuts_styles_with_the_lot() {
// Enqueue the style like this for a theme:
wp_enqueue_style( 'custom-style', get_template_directory_uri() . '/selector/css/multi-select.css', array(), '20120208' );
}
add_action( 'wp_enqueue_scripts', 'wptuts_styles_with_the_lot' );