wp_enqueue_script in the footer

jasonaburton picture jasonaburton · Mar 19, 2012 · Viewed 30.8k times · Source

Having problems enqueuing a script in the footer.

wp_deregister_script('jquery');
wp_enqueue_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js', array(), false, true);

Here's the wp_enqueue_script definition:

wp_enqueue_script( 
     $handle
    ,$src
    ,$deps
    ,$ver
    ,$in_footer 
);

As you can see I am setting $in_footer to true. This does not work for me. Without that argument it works fine and puts it in header.php. Why doesn't it work with $in_footer?

Answer

Com1BOUTIK picture Com1BOUTIK · Feb 5, 2013

By default WordPress default JavaScripts won’t move to the footer, a workaround is to add its path :

wp_enqueue_script('jquery','/wp-includes/js/jquery/jquery.js','','',true);

See detailled post about this