I have a simple jQuery script in a WordPress plugin that is using a jQuery wrapper like this:
$(document).ready(function(){
// jQuery code is in here
});
I am calling this script from within the WordPress Dashboard and am loading it AFTER the jQuery framework has loaded.
When I check the page in Firebug I constantly keep receiving the error message:
TypeError: $ is not a function
$(document).ready(function(){
Should I maybe wrap the script in this function:
(function($){
// jQuery code is in here
})(jQuery);
I have had this error quite a few times and am not sure how to handle it.
Any help would be greatly appreciated.
In WordPress, when you enqueue jQuery (this is for compatibility with other libraries), your solution of wrapping it in function will work, or you can load a bit (but probably not an idea in wordpress), if you have to use document.ready, then you will actually pass $ into the function call: : ‘jQu(function) … .