How do I “unhook” / de-register jQuery so that it’s not called as part of wp_footer();?

You don’t want to unregister the script; that would make it unavailable to be enqueued. Rather, you want to dequeue the script.

You have two choices:

  1. If you know the callback function through which wp_enqueue_script( 'jquery' ) is called, you can simply call remove_action( 'wp_footer', 'callback_function_name' )
  2. More likely, you won’t know the callback function (or jQuery will be enqueued as a dependency by another script), in which case, you can dequeue it directly, which you would do via wp_dequeue_script().

e.g.

function theme_slug_dequeue_footer_jquery() {
     wp_dequeue_script( 'jquery' );
}
add_action( 'wp_footer', 'theme_slug_dequeue_footer_jquery', 11 );

Note: that priority is probably fairly important, since you’ll need to ensure that your dequeue call fires after the enqueue call.

Edit

I’m customizing this theme from the default TwentyEleven theme. It seems as though it’s the theme itself that’s hooking WordPress and not a plugin. I looked in the default functions.php and I don’t see any wp_enqueue_script() in there. Is there somewhere else I should look?

Are you by chance viewing the Showcase Template (i.e. showcase.php)? Note that it enqueues a custom script:

wp_enqueue_script( 'twentyeleven-showcase', get_template_directory_uri() . '/js/showcase.js', array( 'jquery' ), '2011-04-28' );

It adds jQuery to its dependents array, meaning that WordPress will first enqueue jQuery, and then enqueue twentyeleven-showcase. So, that might be the source of the mystery jQuery enqueue.

(There’s also a wp_enqueue_script() call in /inc/theme-options.php, but I don’t think that one would be impacting your front-end script-enqueueing.)

Leave a Comment