jquery-ui-autocomplete is not loaded with wp_enqueue_script

when I load the default jquery-ui-autocomplete script from wordpress via

wp_enqueue_script( 'jquery-ui-autocomplete', '', array( 'jquery-ui-widget', 'jquery-ui-position' ), '1.8.6' );

it is embedded, and all works fine, except the annoying notice message in debug mode:

Read More

Notice: wp_enqueue_script was called incorrectly. Scripts and styles
should not be registered or enqueued until the wp_enqueue_scripts,
admin_enqueue_scripts, or init hooks …

The solution therefore is quite easy, only wrap the wp_enqueue_script call:

function add_scripts(){
  wp_enqueue_script( 'jquery-ui-autocomplete', '', array( 'jquery-ui-widget', 'jquery-ui-position' ), '1.8.6' ); //don't loads the autocomplete
  wp_enqueue_script( 'jquery-ui-autocomplete'); //same as above
}
add_action('wp_enqueue_scripts', 'add_scripts'); 

BUT these technique doesn’t embeds the jquery-ui-autocomplete script, only the annoying message disappear. The only way the jquery-ui-autocomplete script is embed, is without wrapping it …

Where is my error? According to the documentation in the codex it should be done by wrapping the call and simply call wp_enqueue_script( 'jquery-ui-autocomplete'); inside.

BR,
mybecks

Related posts

2 comments

  1. Are you sure it is not loading? I tried this(using WordPress 3.6-beta1):

    function add_scripts(){
      wp_enqueue_script( 'jquery-ui-autocomplete' );
    }
    add_action('wp_enqueue_scripts', 'add_scripts');
    

    I got jQuery and jQuery migrate in the header:

    <script type='text/javascript' src='http://localhost/wordpress/wp-includes/js/jquery/jquery.js?ver=1.9.1'></script> 
    <script type='text/javascript' src='http://localhost/wordpress/wp-includes/js/jquery/jquery-migrate.js?ver=1.1.1'></script> 
    

    And jQuery UI in the footer:

    <script type='text/javascript' src='http://localhost/wordpress/wp-includes/js/jquery/ui/jquery.ui.core.min.js?ver=1.10.2'></script> 
    <script type='text/javascript' src='http://localhost/wordpress/wp-includes/js/jquery/ui/jquery.ui.widget.min.js?ver=1.10.2'></script> 
    <script type='text/javascript' src='http://localhost/wordpress/wp-includes/js/jquery/ui/jquery.ui.position.min.js?ver=1.10.2'></script> 
    <script type='text/javascript' src='http://localhost/wordpress/wp-includes/js/jquery/ui/jquery.ui.menu.min.js?ver=1.10.2'></script> 
    <script type='text/javascript' src='http://localhost/wordpress/wp-includes/js/jquery/ui/jquery.ui.autocomplete.min.js?ver=1.10.2'></script> 
    

    Do you have wp_head() and wp_footer() in your theme? Have you tried it with a simple theme and all plugins deactivated?

  2. In order to use wp_enqueue_scripts action and be called by WordPress, the function call wp_head() must be added before the ending tag and the function wp_foot(); must be added before the ending body tag or

Comments are closed.