激活wordpress插件打破jQuery效果

问题描述:

我目前正致力于将名为Rekreato的HTML5模板转换为wordpress主题。我设法设置了一个简单的主题,但是每当我使用jQuery脚本激活任何插件时,我的一些jQuery效果就被打破了。具体来说,我在Firefox调试器中获得 -激活wordpress插件打破jQuery效果

TypeError: jQuery.easing[jQuery.easing.def] is not a function @ jquery.easing.1.3.js:46

这是page in question。你可以看到一半左右的图像滑块不起作用。我留下了一个活动的插件,名为WP eMember。

我已经尝试了许多事情,像配置我的主题作为一个儿童主题,包装jquery.easing.1.3在文档就绪函数,并在代码中移动脚本调用,但无济于事。我甚至不确定缓动脚本是否有问题。答案可能在我面前凝视着我,但我似乎无法弄清楚。提前谢谢了。

编辑:优秀的建议从markratledge。我用wp_register_script()和wp_enqueue_script()将这些脚本放在functions.php中。起初我很困惑,更多的事情被打破了。进一步阅读,我看到,由于Wordpress在其内置的jQuery库中使用noConflict包装,$快捷方式不可用。所以,我浏览了所有在检查器中显示错误的脚本,并用'jQuery'替换了'$'。瞧!一切都很好。再次感谢!

检查出Function Reference/wp enqueue script « WordPress Codex关于如何在WordPress主题中加载JS并避免出现jQuery错误,并显示示例。

您正在通过直接链接加载一堆jQuery,但随后出现wp_head并为插件加载更多jQuery,并发生冲突。即,两个不同的主要jQuery库;检查Firefox控制台以获取所有正在加载的JS的列表。

从这个DOC:

wp_enqueue_script links a script file to the generated page at the right time according to the script dependencies, if the script has not been already included and if all the dependencies have been registered. You could either link a script with a handle previously registered using the wp_register_script() function, or provide this function with all the parameters necessary to link a script.

This is the recommended method of linking JavaScript to a WordPress generated page.