Wp_deregister_script()不起作用后注册新的jQuery

时间:2011-11-09 作者:Craig

我的职能如下。php,它似乎没有加载jQuery。如果我删除wp\\u deregister\\u script()行,它似乎加载了wordpress包含的jQuery,而不是我手动注册的jQuery(我可以看出)。有人知道为什么会这样吗?

function register_scripts() {

        wp_deregister_script(\'jquery\');

        wp_register_script(\'jquery\', \'http://code.jquery.com/jquery-1.7.min.js\', \'1.7\', 1);
        wp_register_script(\'modernizr\', get_bloginfo(\'template_directory\').\'/js/libs/modernizr-2.0.6.min.js\', \'jquery\');    
        wp_register_script(\'plugins\', get_bloginfo(\'template_directory\').\'/js/plugins.js\', \'jquery\', \'\', 1);    
        wp_register_script(\'custom\', get_bloginfo(\'template_directory\').\'/js/script.js\', \'jquery\', \'\', 1);

        wp_enqueue_script(\'jquery\');
        wp_enqueue_script(\'modernizr\');
        wp_enqueue_script(\'plugins\');
        wp_enqueue_script(\'custom\');

    }

    add_action(\'init\', \'register_scripts\');

1 个回复
SO网友:Chris_O

设置依赖项时,它们需要位于一个数组中。

wp_register_script(\'jquery\', \'http://code.jquery.com/jquery-1.7.min.js\', \'1.7\', 1);
wp_register_script(\'modernizr\', get_bloginfo(\'template_directory\').\'/js/libs/modernizr-2.0.6.min.js\', array(\'jquery\') );    
wp_register_script(\'plugins\', get_bloginfo(\'template_directory\').\'/js/plugins.js\', array(\'jquery\'), \'\', 1);    
wp_register_script(\'custom\', get_bloginfo(\'template_directory\').\'/js/script.js\', array( \'jquery\') , \'\', 1);

结束

相关推荐

WP主题jQuery与使用jQuery的插件冲突

我与我管理的一个网站发生jquery冲突。引用此链接:(http://www.terraworldltd.com/pc/business/2056.html ), 产品页面由奇特的缩放组成,当点击图片时,图片会缩小。对jquery的调用是在单节点上完成的。产品的php。代码如下:<?php get_header(); ?> <script> var closebutton=\'<?php bloginfo(\'template_directory\'); ?