Uncaught ReferenceError: jQuery is not defined

I’m trying to put together a WordPress site with a JQuery slider plugin, but the plugin doesn’t display on the page and I always get the above error message.

Despite trying several different fixes suggested in other’s posts I still can’t seem to fix the above error, including putting the script tag in the ‘header.php’ file. Any help would be much appreciated – thanks!

Read More

Relevant code in ‘footer.php’ file

    <!--Load JQuery-->  
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>


</body> 
</html>

The Website:http://www.advanceprojects.com.au/

Related posts

Leave a Reply

6 comments

  1. Scripts always run in a sequential order.

    So basically you are trying to use jQuery even before the jQuery library is loaded.

    Your script is dependent on Nivo which in turn depends on jQuery library.

    Either move the script to the line after the library is loaded, or move the library declaration to the head.

    Also make sure you enclose the script inside DOM Ready handler.

    So the order in which you should be loading these are

    -- jQuery 
      -- Nivo Slider
      -- your script that uses the above 2 libraries.
    
  2. This worked for me.

    Add the line

    wp_enqueue_script('jquery');
    

    This error happened because jquery is not included, and should be included before loading any other script.
    Here is an example:

    firstplugin.php

    <?php
    /*
    Plugin Name: Plugintrial
    Description:  plugin to test jquery
    Version:      1
    Author:       Dismi Paul
    */
    function childtheme_custom_login() {
    wp_enqueue_script('jquery');
    
    wp_enqueue_script('my-custom-script', plugins_url('/test.js', __FILE__));
    ?>
    
        <h1>Welcome to My Homepage</h1>
    
    <p id="intro">My name is Donald.</p>
    <p>I live in Duckburg.<?php echo plugins_url('/test.js', __FILE__); ?></p>
    
        <?php
    }
    
    add_action('login_head', 'childtheme_custom_login');
    

    test.js

    jQuery(document).ready(function()
    {
      jQuery("#intro").css("background-color", "yellow");
    });
    console.log("it works");
    
  3. In a recent version of WordPress this can be caused by core performance improvements:

    Try placing this in your wp.config file:

    /** Absolute path to the WordPress directory. */
    if ( !defined('ABSPATH') )
        define('ABSPATH', dirname(__FILE__) . '/');
    
    define('CONCATENATE_SCRIPTS', false);
    
  4. I am seeing this same issue with WooCommerce and the Siteground Optimizer when Defer Render Blocking Javascript is on, there is a WC script that references jQuery first (seems to be a date picker script setting defaults) – not a custom script I’ve added, and not a plugin as far as I can tell. My scripts use jQuery and come later, and are fine, but this references it in the head tag prior to jQuery being available… Also this only happens while NOT logged in. If you’re logged in, it works fine, log out, broken.

    Turning off the Defer Javascript option in SG Optimizer seems to fix the issue.

  5. Use

    jQuery(document).ready(function(){
        jQuery('#wpns_slider').nivoSlider({effect:'random',slices:2,});
    });
    

    instead of

    jQuery(window).load(function(){
         jQuery('#wpns_slider').nivoSlider({effect:'random',slices:2,});
    });
    

    $(window).load(function() {... }) is explicitly binding to the window’s load event, your code has already fired before jQuery library is loaded. You have to use DOM Ready handler.