问题很可能是noConflict. 默认情况下,每当WordPress将jquery排入队列时,它都会在noConflict 模式,这意味着它不为jQuery 其中默认值为$ 正如你在问题中所说的那样。
See this Dev Resource comment:
当您将依赖于jQuery的脚本排入队列时,请注意WordPress中的jQuery以noConflict模式运行,这意味着您不能使用公共$别名。您必须改用完整的jQuery。或者,使用$快捷方式将代码放在noConflict包装器中
-bcworkz
这意味着您需要更换$( document ).ready() 使用:
jQuery( document ).ready( function( $ ) {
此外,根据您的评论,在定义JQuery之前,您正在脚本中添加的内容(通过查看页面源代码)。如果你用的是普通的
wp_enqueu_script() (您应该使用/学习使用)您需要定义
jquery 进入
$deps 阵列:
wp_enqueue_script(
\'my-irrelevant-handle\', // Script handle to identify your script
get_stylesheet_directory_uri() . /my-script-path.js, // Path to your script relative to style.css
array( \'jquery\' ), // Tells WordPress to add this script after JQuery has been added
\'\', // Optional version number
true // Load this into the footer for speed purposes
);
This looks like a good enqueuing tutorial.