Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End CSS Tricks "Include jQuery in WordPress Theme" snippet

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #27385
    andrews
    Participant

    Gday,

    In the snippets section on this site there is one called "Include jQuery in WordPress Theme" (http://css-tricks.com/snippets/wordpress/include-jquery-in-wordpress-theme/). I am curious as to why this is the recommended method of including jQuery in a theme?

    The guide suggests adding the following to the themes "functions.php" file –

    Code:
    if( !is_admin()){
    wp_deregister_script(‘jquery’);
    wp_register_script(‘jquery’, (“http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js”), false, ‘1.3.2’);
    wp_enqueue_script(‘jquery’);
    }

    Could someone please explain what this code does and why it is the "best way to go about it". I think this site is fantastic but I don’t believe it’s very informative to simply state it’s the "best way" without educating users as to why?

    For example I currently reference jQuery in the header.php file of my WordPress theme (see below), but if the CSSTricks reccomendation is better I’d love to use it, I’d just like to know more please :

    Code:

    Cheers!

    #68863
    Chris Coyier
    Keymaster

    WordPress needs to know if jQuery is loaded or not, so for example, a plugin doesn’t try to load it again and screw stuff up. That is what the function is for.

    http://digwp.com/2009/06/including-jque … right-way/

    But for the admin area, might as well let it use the shipping version so it’s guaranteed to work. And as you can see, the above code still uses the Google version for fast loading and cross-site caching.

    #68841
    andrews
    Participant

    Thank you :D

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Back End’ is closed to new topics and replies.