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 项目中也应该这样写。