Forums

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

Home Forums JavaScript jQuery in WordPress question

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #46546
    JoshWhite
    Member

    I’d like to find out if I’m just doing this wrong or if this is pretty much what other people have experienced as well.

    I’ve got jQuery enqueued into my WordPress header, but I’ve never got jQuery to work as long as it was within the tag. It works perfectly fine if I place the script on the specific template, or the footer. Any time it is within the I get an error saying “jQuery is not defined”.

    Is that normal? Does it matter? Or is something amiss?

    #143620
    Alen
    Participant

    if(!function_exists(‘google_jquery_api’)){
    function google_jquery_api(){
    if(!is_admin()){
    wp_deregister_script(‘jquery’);
    wp_register_script(‘jquery’, (“//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js”), false);
    wp_enqueue_script(‘jquery’);
    }
    }
    add_action(‘wp_enqueue_scripts’, ‘google_jquery_api’);
    }

    Put this in your `functions.php`. And visit [Google jQuery API](https://developers.google.com/speed/libraries/devguide#jquery) for version you need.

    #143599
    JoshWhite
    Member

    Thanks for the reply! I’ll give it a shot.

    Is there a way to maintain the most recent version if jQuery?

    #143600
    Alen
    Participant

    All you have to do is refer to the link for [Google jQuery API](https://developers.google.com/speed/libraries/devguide#jquery) and change the version number in the string, so for 2.0.3:

    `ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js`

    #143604
    JoshWhite
    Member

    Right, but it won’t be automatic, which is a shame. Thanks again for the reply!

    #143606
    chrisburton
    Participant

    @JoshWhite I don’t think that’s a good idea to begin with. If something becomes deprecated in a future version and your script is using it, you have a constant problem.

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