谷歌jQuery / Wordpress jQuery冲突

时间:2012-04-24 20:41:20

标签: jquery wordpress header footer jquery-masonry

我使用jQuery Masonry构建了一个Wordpress主题。我在使用Google托管的jQuery脚本时在本地托管Masonry脚本。砌体工作得很好。但出于某种原因,我需要在页脚中调用Masonry和jQuery,以便Masonry工作。但这样做会禁用各种使用jQuery的Wordpress插件。看来我的插件需要在标题中调用jQuery,而Masonry需要它在页脚中。

如何解决此冲突?

2 个答案:

答案 0 :(得分:1)

您应该使用wp_register_script方法加载jQuery:

function my_init() {
    if (!is_admin()) {
        // comment out the next two lines to load the local copy of jQuery
        wp_deregister_script('jquery');
        wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', false, '1.7.2');
        wp_enqueue_script('jquery');
    }
}
add_action('init', 'my_init');

http://www.ericmmartin.com/5-tips-for-using-jquery-with-wordpress/

答案 1 :(得分:0)