Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

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

share|improve this question
    
What version of WordPress? jquery-ui-autocomplete was added in 3.3 I think... –  webaware Jul 2 '13 at 10:24

1 Answer 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?

share|improve this answer
    
wp_enqueue_scripts loads script for the front end admin_enqueue_scripts loads scripts for back end That was my Problem. Anyway thanks for your help :) –  mybecks Jul 2 '13 at 10:17
1  
yes, you didn't mention that you were working on the back end... –  RRikesh Jul 2 '13 at 11:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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