Wordpress Jquery Confliction with Plugin

三世轮回 提交于 2019-11-27 07:11:28

问题


Hey guys, thanks in advance for your help. I've done my research and I'm a bit stumped with this...

I'm building a Wordpress website for a client and it is going to have an e-store. I'm using wp-ecommerce. All of the store pages are loading with a javascript error:

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. When I delete my jquery script call, the issue goes away and the store works fine. But I need that jquery...

I've read about using WP enqeue to fix the issue:

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.


回答1:


You could try to execute your jquery with a noConflict option 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';



回答2:


Alright, I figured it out... it was the enqueue script that fixed things. I wp(head); 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');
 ?>



回答3:


Have you looked for an answer on https://wordpress.stackexchange.com/?



来源:https://stackoverflow.com/questions/4845483/wordpress-jquery-confliction-with-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!