jasonaburton jasonaburton -5 years ago 175
jQuery Question

Loading jQuery in Wordpress backend getting error: "jQuery is not defined"

I'm in the backend of Wordpress, trying to create a metabox. I put this code at the top of the metabox so that I can use some jQuery to create it:

if (is_admin()){
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js');
wp_enqueue_script( 'jquery' );

I am getting a "jQuery is not defined" error. I tried changing it to the $ as well, and get the same error - "$ is not defined"

EDIT: My actual jQuery code looks like this:

<script type="text/javascript">
$('#management').append('<div class="person"><a href="#" class="remove_person button">Remove Person</a>' + '<p><label for="_name">Name</label><br/>' + '<input type="text" id="_name" name="_name[]" size="25" /></p></div>');
return false;
$('.remove_person').live('click',function () {
return false;

Why is this happening? I checked in developer (chrome extension) and jQuery is listed as a resource so it is recognizing it, but am still getting this error. Any thoughts?


Answer Source

If you are seeing jquery.min.js in the resources area, and you are getting a jQuery is undefined error, that typically means that jQuery is being included farther down the page than your code.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download