wordpress 报错 TypeError: $ is not a function

文章目录

    代码非常简单,第一行就报错了

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

    TypeError: $ is not a function

    估计是 $ 冲突了,果然,修改成下面的代码即可

    jQuery(document).ready(function($) {
    // Code
    });

    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.

    这样写的确是良好的习惯,即使不在 wordpress 项目中也应该这样写。

    关于作者 🌱

    我是来自山东烟台的一名开发者,有感兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊,或者关注我的个人公众号“大象工具”, 查看更多联系方式