0

I have looked but no where seems to cover how to place jQuery into the footer, at least not the way I have it in my theme, is there a way to place the following into the footer?

// Load jQuery
function my_register_jquery_function() {
    wp_deregister_script('jquery');
    wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"), false, '1.7.1');
    wp_enqueue_script('jquery');

    wp_enqueue_script(
        'cookie'
        , get_stylesheet_directory_uri() . '/js/jquery.cookie.js'
        , array('jquery')
    );
    wp_enqueue_script(
        'easing'
        , get_stylesheet_directory_uri() . '/js/jquery.easing.1.3.js'
        , array('jquery')
    );
    wp_enqueue_script(
        'nivo'
        , get_stylesheet_directory_uri() . '/js/jquery.nivo.slider.js'
        , array('jquery')
    );
    wp_enqueue_script(
        'setup'
        , get_stylesheet_directory_uri() . '/js/setup.js'
        , array('jquery')
    );
}

add_action('wp_enqueue_scripts', 'my_register_jquery_function');

1 Answer 1

1

Sure. Set the fifth parameter of wp_enqueue_script or wp_register_script as true, and that script will be placed in the footer.

For example, your line

wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"), false, '1.7.1');

should be

wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"), false, '1.7.1', true);

And if you ever don't need/want to specify a version number, just set the fourth parameter to false.

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

By the way, to make sure you're avoiding any conflicts, I would recommend you prefix the names of all your custom scripts.

7
  • Thanks, but, strange that didn't do anything? Aug 29, 2012 at 13:01
  • 1
    "Hmmm, strange that didn't do anything?" - What actual code did you use?. Note also: de-registering a core script and registering a custom version can and will have unintended consequences. Aug 29, 2012 at 13:04
  • I used wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"), false, '1.7.1', true); Aug 29, 2012 at 13:08
  • "unintended consequences" that doesn't sound good is there a safe way of enqueuing the scripts? Aug 29, 2012 at 13:10
  • 1
    "is there a safe way of enqueuing the scripts?" - Yes: don't de-register core scripts in order to enqueue custom versions. Just use the core-bundled, core-registered version. Aug 29, 2012 at 13:33

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.