Support » Themes and Templates » double jquery, complete mess

  • I’ve unfortunately inherited a really poorly written theme on a site I’m going to maintain.

    In the header, it’s already calling jquery…

    <script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/js/jquery.js"></script><br />
        <script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/js/scripts.js"></script><br />
          <script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/js/prettyPhoto/js/jquery.prettyPhoto.js"></script>  </p>
    <p>    <?php wp_head(); ?>

    As soon as I install any plugin with jquery (nextgen gallery for example) that gets added to the header, everything starts to break.

    I know it’s because it’s loading jquery twice, but here’s the kicker, removing the original call from the header.php breaks everything. Homepage slider, dropdown menus, the whole shebang. I think whoever wrote this put in a bunch of dependencies to it all over the place.

    If I use the function in NGG to stop the scripts from loading…


    …then the menus/sliders work again, but it kills off Nextgen’s galleries and lightboxes.

    I’m completely confused as to where to start fixing this.

    In a perfect world, if I could get either the theme to stop loading jquery OR nextgen to only load jquery when it’s used (or, just NOT on the homepage) then I’d be all set. I can’t seem to accomplish either.

    Anyone have any idea what I’m talking about? I’ve been staring at this for way too long and I think I’m just confusing myself more and more. HELP!

Viewing 10 replies - 1 through 10 (of 10 total)
  • Have you tried enqueueing your scripts?

    I did actually. I tried…

    <?php wp_enqueue_script('jquery');

    …in the header in place of the script call. It didn’t load at all and the navigation and home page slider stopped working.

    This is what the entire header looks like if I enable NextGen…

    [Large code excerpt removed by moderator. Per forum rules, please use the pastebin for all large code excerpts. It works better anyway.]

    Like I said, it’s a trainwreck. I inherited this problem from someone else. They “love” their theme and don’t want to change it, and just want “this to work”.

    No – you don’t enqueue jQuery. You enqueue your custom script and make it dependant on jQuery. Personally, I enqueue scripts in functions.php and use the template_redirect action:

    function init_myscript() {
        get_bloginfo('template_directory') . '/myscript.js',
    if( !is_admin() ) add_action('template_redirect', 'init_myscript');

    Ohhhh, ok, I gotcha. So, would I then remove both jquery and the scripts.js from the header and replace it with “wp_enqueue_script(‘myscript’)” ?

    Using a function similar to the one I gave above, you’d remove both jquery and the scripts.js from the header – full stop. You don’t need to add anything other than the function. The function itself is instructing WP to add the scripts appropriately.

    Gotcha. I’ll give that a try this afternoon. Thank you so much for the help! I’ll let you know if it works.

    Unfortunately, it didn’t work. I added that to my functions.php and removed the scripts from the header.php. It broke my front page slider. Actually, any time I remove the jquery link from the header, it instantly breaks. I don’t understand how the theme can be so dependent on it being hardlinked like that. 🙁



    I am also having this issue.

    I basically added the above code block within PHP tags to my functions file, updating the URL and name of the script I want to be included, and it doesn’t do anything – WP still loads jQuery below my jquery-functions file and screws everything up.



    In the end, what I ended up doing was removing just about everything from the header above the wp_head call, then adding whatever script I was calling, like…

    <?php wp_head(); ?>
    	<script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/js/scripts.js"></script>

    Then, in my functions.php, I basically unloaded and reloaded jquery…

    if( !is_admin()){
    wp_register_script('jquery', (""), false, '1.4.2', false);

    That seems to be working for me. It’s not a perfect solution, but it’s worth trying. Good luck!

    Thanks DocHoloday, I have same problem and it also work for me.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘double jquery, complete mess’ is closed to new replies.