我的职能如下。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\');
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);