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.

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

wp_enqueue_script('suggest');

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

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

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

//update

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:

<?php
//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_enqueue_script('jcrop');
wp_enqueue_style('jcrop');
wp_deregister_script('suggest'); //workaround
wp_register_script('suggest', '/wp-includes/js/jquery/suggest.js'); //workaround
wp_enqueue_script('suggest'); //workaround

...

get_header();

page content that uses scripts & styles

get_footer();
?>

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…

share|improve this question
    
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' )? –  m0r7if3r 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

1 Answer 1

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.

share|improve this answer

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.