1

I am working with HTML5 Blank and I can't seem to get jquery to stop being called in wp_footer(). I have tried adding this to the bottom of my functions file:

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

with no luck. I also tried:

if( !is_admin()){
wp_deregister_script('jquery');
wp_dequeue_script('jquery');}

but I still end up with /wp-includes/js/jquery/jquery.js?ver=1.8.3 being called in the footer. What am I doing wrong here?

3
  • 1
    Just to get you right: don't you want jQuery being enqueued at all, or do you just want it to be enqueued in the header rather than in the footer?
    – tfrommen
    Mar 12, 2013 at 3:46
  • Do you know what is enqueuing the script? If you dequeue this, whatever is using it could well stop working.
    – s_ha_dum
    Mar 12, 2013 at 3:51
  • @tf I want it gone entirely. s_ha_dum: I'm not sure, but I am fine with that outcome. Mar 12, 2013 at 4:13

2 Answers 2

1

If your working with a blank theme why don't you just remove or comment out the wp_enqueue_script('jquery'); in the theme functions.php?

Otherwise your action hook is wrong, use,

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

This will still load the build in jQuery (I think) in /wp-includes/js/jquery/jquery.js?ver=1.8.3

To remove all jQuery from the admin & the front end you have to deregister_script, this will break how the admin functions but it will still be usable (no drag and drop, etc).

add_action('wp_print_scripts','theme_slug_dequeue_footer_jquery');
function theme_slug_dequeue_footer_jquery() {
        wp_deregister_script('jquery');
        wp_dequeue_script('jquery');
    }

Also for just the front end use (this is the one you should be using):

 add_action('wp_print_scripts','theme_slug_dequeue_footer_jquery');
 function theme_slug_dequeue_footer_jquery() {
       if( !is_admin()){
           wp_dequeue_script('jquery');
       }
}
3
  • I tried your last block of code there but 1.8.3 is still being called in the footer :( The reason I wanted to do this was because I need to call an older version of jquery in the header before the main page content loads - maybe there is a better way than dequeueing? Mar 12, 2013 at 6:56
  • No, disable plugins and switch to the default theme.
    – Wyck
    Mar 12, 2013 at 15:58
  • I see now that other includes in my functions file were calling jquery as a dependency ( this post helped wordpress.stackexchange.com/a/35039/27454 ) but your answer was also very helpful and technically correct based on the limited info I provided so thank you! Mar 12, 2013 at 17:26
0

If you need to call another jQuery version, you could use the noConflict method and you can load them in header or footer with no problem in any order.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.