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
Are you sure it is not loading? I tried this(using WordPress 3.6-beta1):
I got jQuery and jQuery migrate in the header:
And jQuery UI in the footer:
Do you have
wp_head()
andwp_footer()
in your theme? Have you tried it with a simple theme and all plugins deactivated?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