i'm not able to enqueue the built in autosuggest script in my wordpress theme.


my current workaround for that problem is to deregister, register manually an then enqueue it – like so:

wp_register_script('suggest', '/wp-includes/js/jquery/suggest.js');

i can't figure out how to solve this problem, because i get no error at all (WP_DEBUG defined TRUE)

thanks for your thoughts, hans


sorry for being a bit cloudy with the description of my problem:

i am working on a wiki-like thing based on wordpress. there is one page where users can upload new images and tag them (this is where i need the suggest.js).

the templatefile for this page looks like:

//enqueue scripts + styles
wp_enqueue_script('uploadify', get_bloginfo('template_directory') . '/js/uploadify/jquery.uploadify.v2.1.0.js', array('jquery'), null, null);
wp_enqueue_script('swfobject', get_bloginfo('template_directory') . '/js/uploadify/swfobject.js', array('jquery'), null, null);
wp_deregister_script('suggest'); //workaround
wp_register_script('suggest', '/wp-includes/js/jquery/suggest.js'); //workaround
wp_enqueue_script('suggest'); //workaround



page content that uses scripts & styles


at the very beginning of the file i'm enqueueing the additional styles/scripts i need for that single page. (other "basic" scripts + styles get enqueued in my functions.php)

enqueueing jcrop for example works without any problems…

  • You'll need to show where you hook that, so better place a big portion of surrounding code as well. You should also tell from where and for what purpose you're trying to do this. – kaiser Mar 8 '12 at 14:07
  • What do you get if you wp_print_script( 'suggest' )? – mor7ifer Mar 8 '12 at 14:07
  • I tried to replace wp_enqueue_script by wp_print_script. doesn't seem to change anything… – hans Mar 8 '12 at 16:58
  • See solution with explanation below. Please mark as solution if it works. – kaiser Mar 8 '12 at 18:11
  • For me it looks like your solution would load suggest.js on every page. I only want it to be loaded on one specific page. Anyway, thanks for bringing up the hint that one should use hooks to include scripts! (I'm using the 'init' hook to enqueue my scripts in function.php – is this fine too?) – hans Mar 9 '12 at 10:58

As stated on WP Devel, you should always use the appropriate hooks. Else no child theme could deregister the script later.

// In your functions.php file
function add_suggest_script()
    wp_enqueue_script( 'suggest', get_bloginfo('wpurl').'/wp-includes/js/jquery/suggest.js', array(), '', true );
add_action( 'wp_enqueue_scripts', 'add_suggest_script' );

This will load the script from the includes folder and stick in your footer (where a script ideally should be).

You could also use includes_url() in the function above. This will also check for SSL connections.

Note: You'll have to have wp_head(); present. Inside there the mentioned hook gets fired.

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.