1

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

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

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?

  • 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
0

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

  • There is no function like wp_foot, it's called wp_footer – bravokeyl Oct 29 '16 at 6:47

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.