根据我的代码这篇博文中展示了 http://beneverard.co.uk/blog/wordpress-loading-jquery-correctly/, 这个怎么样:
function load_jquery() {
// only use this method is we're not in wp-admin
if (!is_admin()) {
// deregister the original version of jQuery
wp_deregister_script('jquery');
// discover the correct protocol to use
$protocol='http:';
if($_SERVER['HTTPS']=='on') {
$protocol='https:';
}
// register the Google CDN version
wp_register_script('jquery', $protocol.'//ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js', false, '1.5.2');
// add it back into the queue
wp_enqueue_script('jquery');
}
}
add_action('template_redirect', 'load_jquery'
我使用模板重定向挂钩,我想知道这是否是导致您出现问题的原因。
无论哪种方式,如果这不起作用,您能否提供有关该问题的更多信息,您有该网站的链接吗?
Edit
哦,你的函数还打开了 PHP 标签,而实际上它们应该已经打开了,请参阅我的评论......
function googlejqueryhost(){
<?php // HERE, remove this
wp_unregister_script('jquery');
wp_unregister_script('jquery-ui-core');
wp_enqueue_script('jquery', https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js);
wp_enqueue_script('jquery-ui-core', https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.min.js);
?> // AND HERE, remove this
}
Edit 2
您会注意到您的网站现在可以从 Google 的 CDN 正确加载 jQuery,其他脚本与 jQuery 库本身无关。