Uncaught ReferenceError: jQuery is not defined

39,687

Solution 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.

Solution 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");

Solution 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);

Solution 4

See The Link How to add css and Js File

http://codex.wordpress.org/Function_Reference/wp_enqueue_script

Probably Before JQuery,Your Js File Is Loaded.

So add js file after Jquery file is Loaded

Example

wp_enqueue_script("yourjs","yourjspath",array('jquery'), true);
Share:
39,687
user2541351
Author by

user2541351

Updated on February 13, 2020

Comments

  • user2541351
    user2541351 about 4 years

    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!

    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/

  • Dave
    Dave over 2 years
    This did the trick for me. Thank you!