I looked at the included scripts in WordPress (wp_enqueue_script) and didnt find what I should include to use jQuery UI Autocomplete

I am using it in the admin area. Should I just include jQuery UI from Google CDN? I think it will conflict with WordPress's jQuery UI? It appears to work tho.


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 );

I'm just beginning to play around with registering scripts, adding my own etc. I believe it's OK to use the Google CDN as long as you deregister the WordPress version (only when viewing the website, not in the Admin area).

I believe the correct way to do this is to use the if ( !is_admin ()... way. This will ensure everything continues to work correctly in the Admin Area, but still allows you to take advantage of the Google CDN.

Here is an example:

if ( !is_admin() ){
   wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"), false, '1.3.2');

I believe that is how to achieve what you're asking, but I would like to hear some of the "Guru's" suggestions on this.


I should have noticed that you are using this in the admin area since it's clearly stated in your question. Here is the way suggested in the WP Codex Function Reference/wp enqueue script:

function my_init_method() {
    if (!is_admin()) {
        wp_deregister_script( 'jquery' );
        wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js');
        wp_enqueue_script( 'jquery' );
add_action('init', 'my_init_method');
  • I am using it in the admin section tho – JM at Work Jul 8 '11 at 2:37
  • My first answer wasn't 100% correct. I've recently learned to exclude js from the admin area you use: wp_register_script('custom_script', get_bloginfo('template_directory') '/js/custom_script.js',.......... I'm sorry if my comment was misleading. I'm still learning as the in's and outs. . So either method I've give should work. – Jeremy Jared Jul 8 '11 at 3:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.