How to stop loading multiple copies of jquery

You should remove these lines from your header.php

<script language="javascript" type="text/javascript" src="https://wordpress.stackexchange.com/questions/154191/<?php bloginfo("template_url'); ?>/javascripts/jquery.js"></script>
<script language="javascript" type="text/javascript" src="https://wordpress.stackexchange.com/questions/154191/<?php bloginfo("template_url'); ?>/javascripts/tabber.js"></script>
<script language="javascript" type="text/javascript" src="https://wordpress.stackexchange.com/questions/154191/<?php bloginfo("template_url'); ?>/javascripts/superfish.js"></script>

And instead add the following function in your functions php…
right at the top.

wp_enqueue_script

function sg_theme_js(){

    wp_enqueue_script( 'jquery' );
    wp_enqueue_script( 'tabberjs', get_template_directory_uri().'/javascripts/tabber.js', array('jquery'), 1.0, true);
    wp_enqueue_script( 'superfishjs', get_template_directory_uri().'/javascripts/superfish.js', array('jquery'), 1.0, true);

}
add_action( 'wp_enqueue_scripts', 'sg_theme_js' );

Explenation:
Since many plugins use jQuery (and other js files) they need to know (and wordpress too) that you already loaded jQuery… but, they cannot check it after the page has loaded meaning by checking your header becouse that is too late!

That is why we should enqueue scripts and those allow plugins to depened on them.

Now… a small comment.
if you wish to manage your theme meaning deal with code you need to learn this stuff 😉 – take a moment to read about wp_enqueue_script.

Here is additional information about: wp_enqueue_script

Leave a Comment