jQuery UI AutoComplete & wp_enqueue_script

The jQuery autocomplete is not come with WP package. So you have to download this component from jQuery UI and enqueue it for use. Using jQuery UI at Google CDN also works, but in my opinion, that’s not very good, because you will load whole the jQuery UI lib while you need only one component.

This is the code I used to load jQuery autocomplete (in a plugin):

add_action( 'admin_menu', 'wpse_21556_admin_menu' );

function wpse_21556_admin_menu() {
    $page = add_management_page( 'Plugin', 'Plugin', 'manage_options', 'plugin-page-hook', 'wpse_21556_plugin_page' );

    add_action( "admin_print_styles-{$page}", 'wpse_21556_admin_print_styles' );
}

function wpse_21556_admin_print_styles() {
    // jQuery autocomplete
    wp_enqueue_style( 'jquery-ui-autocomplete', plugins_url( 'css/jquery-ui-1.8.2.custom.css', __FILE__ ) );
    wp_register_script( 'jquery-ui-autocomplete', plugins_url( 'js/jquery.ui.autocomplete.min.js', __FILE__ ), array( 'jquery-ui-widget', 'jquery-ui-position' ), '1.8.2', true );

    // Plugin script and style
    wp_enqueue_style( 'plugin-css', plugins_url( 'css/style.css', __FILE__ ) );
    wp_enqueue_script( 'plugin-js', plugins_url( 'js/script.js', __FILE__ ), array( 'jquery-ui-autocomplete' ), '1.1', true );
}