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 currently enque jQuery like so - how do I move this to the footer instead?

// Enque: jQuery
if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
   wp_deregister_script('jquery');
   wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null);
   wp_enqueue_script('jquery');
}
share|improve this question
    
Why do you need to move it to the footer? What are you trying to that requires you to deregister core's jquery? –  Andrew Bartel May 2 '13 at 18:14
1  
Why even replace the internal library? (with an older version mind you) Is there some special functionality that version provides that you need? Additionally you don't need that is_admin() check, that action doesn't run in the admin. –  t31os May 2 '13 at 18:48
    
Also, the last param of both wp_enqueue_script and wp_register_script defines whether to load the script in the footer. –  t31os May 2 '13 at 18:50

2 Answers 2

up vote 3 down vote accepted

The fifth parameter is $in_footer. You have left that out. Add that parameter, set it to true.

wp_register_script(
  'jquery',
  "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js",
  false,
  null,
  true
);

But I echo the concern expressed by @Andrew in a comment. You can cause yourself trouble by deregistering/replacing the core libraries.

Reference

http://codex.wordpress.org/Function_Reference/wp_register_script

share|improve this answer

wp_register_script() takes boolean for last argument $in_footer (default false) to achieve this.

Note that it is strongly considered best practice to use same version WP core uses (determined by code) rather than hardcode arbitrary one.

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.