有人建议我使用wp_unregister和wp_enqueue将wordpress jquery库替换为谷歌托管的库(因为wordpress one有一些问题)
然而,当我试图将它们插入到我的wordpress站点中时,它破坏了我的站点。
我需要以某种方式包装它们吗?
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);我的网站有一个自定义文件夹,我可以在其中放置自定义函数。我试过了,但没有成功
function googlejqueryhost(){
<?php
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);
?>
}
add_action('wp_head', 'googlejqueryhost');发布于 2011-07-06 21:23:04
根据我使用demonstrated in this blog post编写的代码,如下所示:
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'我使用了模板重定向钩子,我想知道这是否是导致您的问题的原因。
无论哪种方式,如果这不起作用,你能提供更多关于这个问题的信息,你有网站的链接吗?
编辑
哦,还有你的函数打开了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
}编辑2
你会注意到你的站点现在可以从谷歌的CDN正确加载jQuery了,另一个脚本与jQuery库本身没有任何关系。

https://stackoverflow.com/questions/6597034
复制相似问题