如何修复两个版本的jquery冲突

时间:2013-06-14 17:33:36

标签: jquery wordpress

<script type='text/javascript' src='http://labellaintimates.com/wp-includes/js/jquery/jquery.js?ver=1.8.3'></script>
<script type="text/javascript" src="http://labellaintimates.com/wp-content/themes/labella/jquery.js"></script>

有一个jquery冲突,你能帮我解决一下吗?

2 个答案:

答案 0 :(得分:3)

我认为这里发生的事情是WordPress正在加载它自己的jQuery版本,你也可以从你的主题手动加载一个。

在您的函数文件中,包含以下脚本:

function my_scripts_method() { // Creates the my_scripts_method function
    wp_deregister_script('jquery'); // Deregisters the built-in version of jQuery
    wp_register_script('jquery', 'http' . get_template_directory_uri() . '/YOUR-JS-PATH.js', false, null, true); // Registers your javascript file
    wp_enqueue_script('jquery'); // Activates the jQuery script
}
add_action('wp_enqueue_scripts', 'my_scripts_method'); // Tells WordPress to run the my_scripts_method function

我怀疑你的主题(或插件)可能已经在注册你的本地jQuery文件了,而且根本没有取消注册一个WordPress包含,所以你应该挖掘一下以确保你没有调用同一个文件两次。

更新 - 您可以在此处找到更多详细信息:http://gomakethings.com/jquery-wordpress/

答案 1 :(得分:0)

你只需要一个。它们都是相同的东西,但可能是不同的版本。如果你的一个脚本在删除之后中断了,那么你的脚本可能不适用于那个特定版本,但在大多数情况下应该可以正常工作。