Why is jquery-ui-core enqueueing in my footer instead of the header?

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?

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' );
}

Leave a Comment