WordPress: How to wp_enqueue_script jquery-ui / autocomplete

If you are trying to enqueue jquery’s autocomplete in wordpress, I’d suggest just using the remote version through google’s CDN / API site. You can deregister the jquery-ui with the first line of code, re-register it with the second line of code, and then activate it with the third line of code:


You may also want to enqueue the styles using something like:

wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css'); 

And more recently I found this project on GitHub which has some nice examples and code that may be more updated than the version included with wordpress:


Related Posts:

  • No Related Posts
This entry was posted in Web Development and tagged , , , . Bookmark the permalink.

4 Responses to WordPress: How to wp_enqueue_script jquery-ui / autocomplete

  1. Tássio Dias says:

    Hi Mark, after much searching and think I came to this solution:

    wp_enqueue_script('jquery'); wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('jquery-ui-widget'); wp_enqueue_script('jquery-ui-position'); wp_register_script('jquery-ui-autocomplete', $plugin_url . '/js/jquery.ui.autocomplete.js', array( 'jquery-ui-widget', 'jquery-ui-position' ), '1.8.2', true ); wp_enqueue_script( 'jquery-ui-autocomplete', $plugin_url . '/js/jquery.ui.autocomplete.js', '1.1', true );


  2. Mark says:

    Thanks for this, it saved my butt, to bad that wordpress won’t integrate it as part of the library. The “suggest” function they tell you to use instead didn’t cover the needs I had. Why won’t they give devs a choice? What’s up with this?

  3. Marc says:

    Hi Sven,

    You’re right that this is not the “wordpress” way, but the only problem is that the autocomplete function is not included in the wordpress library so it has to be added somehow. It is a lot trickier to separate out the autocomplete library and try to manually add it into a wordpress install, and then enqueue it and have it work properly, so that’s why I’ve posted (and use) this solution.

    If you can come up with a better way to get the autocomplete functionality working I’d love to hear it.


  4. Sven Wagener says:

    Thats nice, but your solution isn’t the wordpress conform way. You have to use the wordpress jquery because otherwise you can get issues with wordpress. The wordpress way would be to use the wordpress jQuery and load all additional jQuery functions you need.

    For example (jQuery Accordion):

    wp_enqueue_script( 'jquery-ui' ); wp_enqueue_script( 'jquery-ui-widget' );

    wp_register_script( 'jquery-ui-accordion', $js_path . '/jquery.ui.accordion.js', array( 'jquery' ), '1.8.9', true ); wp_enqueue_script( 'jquery-ui-accordion' );

    Bye Sven!

Leave a Reply

Your email address will not be published. Required fields are marked *