Google jQuery / Wordpress jQuery Conflict



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

如何解决此冲突?

你应该使用 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/

这可能是兼容性问题吗?

http://docs.jquery.com/Using_jQuery_with_Other_Libraries

最新更新