How Do I Use jQuery UI In My Plugin

Given that all of the libraries you need for the datepicker are bundled with WordPress and are registered with all of the appropriate dependencies, all you really need to do is:

function enqueue_my_scripts_wpse_97533() {
  wp_enqueue_script('jquery-ui-datepicker');
}
add_action('wp_enqueue_scripts','enqueue_my_scripts_wpse_97533');

If you then look at the source of the page you will see that jQuery, jQuery-UI, and jQuery-UI-Datepicker are all loaded.

Of course, you will need to load any other scripts yourself in pretty mush the way you already are, though you should register them with their dependencies– third parameter.

wp_register_script( $handle, $src, $deps, $ver, $in_footer ); 

For example…

wp_register_script(
    'maskedinput',
    SSM_PLUGIN_URL.'/includes/js/jquery.maskedinput.min.js',
    array('jquery')
);

That way, you could load that with…

function enqueue_my_scripts_wpse_97533_v2() {
  wp_enqueue_script('maskedinput');
}
add_action('wp_enqueue_scripts','enqueue_my_scripts_wpse_97533_v2');

… and know that the dependencies– jQuery– will get loaded as well.

Leave a Comment