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.

This is what I'm using to make sure that I have jquery-ui-core available:

if (!is_admin()) add_action('wp_enqueue_scripts', 'zg_load_scripts');
function zg_load_scripts(){
    wp_enqueue_script("jquery-ui-core");
} 

I also tried wp_enqueue_script("jquery-ui-core", null, null, false, false); in a vain attempt to force it into the header. No dice. What's going on here?

share|improve this question

1 Answer 1

Why do you need it in the header?

It's enqueuing in the footer because when it was registered it was set to enqueue in the footer.

In wp-includes/script-loader.php:

$scripts->add( 'jquery-ui-core', '/wp-includes/js/jquery/ui.core.js', array('jquery'), '1.8.12' );
$scripts->add_data( 'jquery-ui-core', 'group', 1 );

The second line forces it to load in the footer. You could deregister the script, then re-enqueue it in the header:

<?php
add_action('wp_enqueue_scripts', 'zg_load_scripts');
function zg_load_scripts(){
    if( is_admin() ) return;
    wp_deregister_script( 'jquery-ui-core' );
    wp_enqueue_script( 'jquery-ui-core', site_url(  '/wp-includes/js/jquery/ui.core.js' ), array('jquery'), '1.8.12' );
}
share|improve this answer
    
Thanks, Christopher. The missing link for me was wp-includes/script-loader.php. That's some good info there. You mention that it's being registered to enqueue in the footer, but where do you see that? I'm looking for wp_register_script() there but only see direct calls on the $scripts object. –  Tom Auger Sep 1 '11 at 16:45
2  
Interestingly, as soon as I wp_enqueue_script() some other (custom) script and mark jquery-ui-core as a dependency, jquery-ui-core is popped to the header! –  Tom Auger Sep 1 '11 at 16:46
    
I'm not entirely sure if the script loader thing matters -- it says it's for admin only, but it hooks into wp_default_scripts which isn't an admin-only thing. Awesome that it works if you enqueue another as a dependency. I suppose that's because the other script is in the header and WordPress puts ui-core above it. Less work than my solution. –  chrisguitarguy Sep 1 '11 at 16:49
1  
You should post what you did as an answer, by the way. And mark this as accepted so other folks who have the same question can figure it out. –  chrisguitarguy Sep 1 '11 at 17:07

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.