简体   繁体   English

Wordpress Jquery 与插件冲突

[英]Wordpress Jquery Confliction with Plugin

I am building a Wordpress website for a client and it is going to have an e-store.我正在为客户建立一个 Wordpress 网站,它将有一个电子商店。 I'm using wp-ecommerce.我正在使用 wp-ecommerce。 All of the store pages are loading with a javascript error:所有商店页面都加载了 javascript 错误:

http://www.thecollectiveclothingco.com/products-page/t-shirts/ http://www.thecollectiveclothingco.com/products-page/t-shirts/

jQuery("form.product_form").livequery is not a function
[Break On This Error] jQuery("form.product_form").livequery(function(){ 

After some extensive google-age, I believe I've diagnosed the issue as a script conflict.经过一些广泛的谷歌时代后,我相信我已经将该问题诊断为脚本冲突。 In other words, either WP or the plugin itself is serving up jquery, and I'm also including it for some other things on the site.换句话说,无论是 WP 还是插件本身都在提供 jquery,我还将它包含在网站上的其他一些内容中。 When I delete my jquery script call, the issue goes away and the store works fine.当我删除我的 jquery 脚本调用时,问题就消失了,商店工作正常。 But I need that jquery...但我需要那个jquery...

I've read about using WP enqeue to fix the issue:我已经阅读了有关使用 WP enqeue 解决问题的信息:

function my_init_method() {
    if (!is_admin()) {
        wp_deregister_script( 'jquery' );
        wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js');
        wp_enqueue_script( 'jquery' );
    }
}    
add_action('init', 'my_init_method');php wp_head(); 

I believe I've done this right, but does not seem to be fixing anything.我相信我做得对,但似乎没有解决任何问题。

Any ideas?有什么想法吗? Thanks again.再次感谢。

You could try to execute your jquery with a noConflict option http://api.jquery.com/jQuery.noConflict/您可以尝试使用 noConflict 选项执行 jquery http://api.jquery.com/jQuery.noConflict/

eg,例如,

var j = jQuery.noConflict();
// Do something with jQuery
j("div p").hide();
// Do something with another library's $()
$("content").style.display = 'none';

Alright, I figured it out... it was the enqueue script that fixed things.好吧,我想通了......是解决问题的入队脚本。 I wp(head);我 wp(头); had to come before the deregister and enqueue part.必须在取消注册和入队部分之前出现。 I must have read the documentation wrong.我一定是读错了文档。 Here's what I added to my header:这是我添加到标题中的内容:

<?php
wp_head();
wp_deregister_script('jquery');
wp_enqueue_script('jquery', MYURL .'http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js', FALSE, '1.4.4');
 ?>

您是否在https://wordpress.stackexchange.com/上寻找答案?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM