TypeError: $ is not a function Wordpress

2019-01-06 12:38发布

I might have an error in a .js document in a theme I have purchase:

$('.tagcloud a').wrap('<span class="st_tag" />');

I am trying to solve it but I am not a programmer so I don't know how. The site is this: http://www.framerental.com .

10条回答
Deceive 欺骗
2楼-- · 2019-01-06 13:09

I added a custom script file that loaded at the end of the head section, and inserted the following at the top:

(function (jQuery) {
    window.$ = jQuery.noConflict();
})(jQuery);

(This is a modification of Fanky's answer)

查看更多
Deceive 欺骗
3楼-- · 2019-01-06 13:10

If you have included jQuery, there may be a conflict. Try using jQuery instead of $.

查看更多
在下西门庆
4楼-- · 2019-01-06 13:11

Instead of doing this:

$(document).ready(function() { });

You should be doing this:

jQuery(document).ready(function($) {

    // your code goes here

});

This is because WordPress may use $ for something other than jQuery, in the future, or now, and so you need to load jQuery in a way that the $ can be used only in a jQuery document ready callback.

查看更多
ゆ 、 Hurt°
5楼-- · 2019-01-06 13:11

jQuery might be missing.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>

查看更多
登录 后发表回答