PHP function to load jQuery in WordPress footer

Loading stuff on the footer simply makes your site load faster.

A word of caution: I have no is this working with plugins.

function load_jquery() {
    // Only use this method when not in wp-admin
    if (!is_admin()) {
        // Discover the correct protocol to use
        $protocol = 'http:';
            if ($_SERVER['HTTPS']=='on') {
            $protocol = 'https:';

        // Settings for the script, change these to your liking

        // jQuery version you want
        $jquery_version = '2.0.3';
        // The url you want it from. Default to Google CDN
        $jquery_url = $protocol . '//' . $jquery_version . '/jquery.min.js';
        // Load in footer, default to footer
        $footer_load = true;

        // Deregister the original version of jQuery
        // Register the new version
        wp_register_script('jquery', $jquery_url, false, $jquery_version, $footer_load);
        // Add it back into the queue
add_action('template_redirect', 'load_jquery');
add_action('wp_enqueue_scripts', 'my_scripts_method');

That goes into your themes functions.php file.

Further reading

Club-Mate, the beverage →