Grow your CSS skills. Land your dream job.

why does my theme need jQuery (twice) to work?

  • # March 3, 2013 at 10:42 pm

    I’m adding [this responsive nav script](http://media02.hongkiat.com/responsive-web-nav/demo/index.html “”) to my theme. It requires putting this into the code:

    http://codepen.io/anon/pen/ACwjc

    But I’d prefer to stick the jQuery link in functions.php, like this -

    wp_register_script( ‘jquery’, ‘http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js’, null, ’1.7.2′, false);

    But when I do that, the navigation no longer works. If I have links to the Google ajax libraries in both places it works fine. Why does it matter where I put the link?

    # March 3, 2013 at 10:44 pm

    To clarify, this is what’s in the header:

    http://codepen.io/anon/pen/lnpJE

    If I remove the second reference to the Google ajax library, the navigation fails.

    # March 4, 2013 at 4:19 am

    Im assuming that you are using wordpress. Chris Coyier posted a nice little function to include inside your functions.php.

    This is the one i use and never have any problems:

    if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
    function my_jquery_enqueue() {
    wp_deregister_script('jquery');
    wp_register_script('jquery', "http" . ($_SERVER == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js", false, null);
    wp_enqueue_script('jquery');
    }

    Here is the article.

    # March 4, 2013 at 1:17 pm

    Thanks John. For some reason that doesn’t fix it.

    This code is what functions.php generates, but doesn’t help the nav work -

    ``

    Hard-coding this is the only thing that works -

    ``

    # March 4, 2013 at 3:03 pm

    where is your wp_head(); function located? Try moving that to just before the closing head element if it’s not already there. WP loads up a ton of stuff, sometimes extra junk, with that one function.

    # March 4, 2013 at 3:05 pm

    Do you have a live site? Would make it easier to see what’s going on.

    # March 4, 2013 at 3:10 pm

    I’m developing this theme locally, but my functions.php section looks like this -

    http://d.pr/i/VwBp

    And the head stuff looks like this -

    http://d.pr/i/owzq

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

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