Skip to content

WordPress function to load jQuery from Google’s CDN.

    Loading jQuery using Google’s Content Delivery Network(CDN) will lead to decreased latency, meaning faster load time for your site. Using this method eliminates a request from your server. In some cases the user may already have the exact version of jQuery cached from Google’s CDN, meaning they do not need to download it again. However, if you host jQuery locally from your site, the user must download it, even if it is the same version.

    To load jQuery from Google’s CDN, add the following to your functions.php file in your theme.
    Remember to change the version of jQuery with the version you want.


    function load_jquery() {
    if (!is_admin()) {
    wp_deregister_script('jquery');
    wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js', false, '1.11.1', true);
    wp_enqueue_script('jquery');
    }
    }
    add_action('wp_enqueue_scripts', 'load_jquery');

    Say Hello!

    adeeb@adeeb.org


    Let’s work together!

    I’ve been building websites since dialups walked the earth.
    I develop, design, architect & maintain websites.

    © Copyright 2009 – Forever Adeeb