Grow your CSS skills. Land your dream job.

jQuery in WordPress question

  • # July 19, 2013 at 6:00 pm

    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?

    # July 19, 2013 at 7:38 pm

    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.

    # July 20, 2013 at 12:23 am

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

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

    # July 20, 2013 at 12:51 am

    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`

    # July 20, 2013 at 2:21 am

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

    # July 20, 2013 at 4:40 am

    @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)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".