- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有人建议我使用 wp_unregister 和 wp_enqueue 将 wordpress jquery 库替换为 google 托管的库(因为 wordpress 有一些问题)
但是,当我尝试将这些插入我的 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');
最佳答案
基于我的代码 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'
我使用模板重定向 Hook ,我想知道这是否是导致您出现问题的原因。
无论哪种方式,如果这不起作用,您能否提供有关该问题的更多信息,您有该网站的链接吗?
编辑
哦,你的函数还打开了 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
您会注意到您的网站现在可以从 Google 的 CDN 正确加载 jQuery,其他脚本与 jQuery 库本身无关。
关于jquery - wp_unregister 和 wp_enqueue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6597034/
我正在尝试创建一个 WordPress 主题并开始学习使用 wp_enqueue 包含 javascript 和 css 文件的最佳方法。几个小时后,我仍然无法加载文件。这是我使用的代码 functi
有人建议我使用 wp_unregister 和 wp_enqueue 将 wordpress jquery 库替换为 google 托管的库(因为 wordpress 有一些问题) 但是,当我尝试将这
如果需要,我在 html 中使用媒体查询来加载新的网格样式表。我可以将其翻译为在我的functions.php 中工作吗? wp_register_style('html5blank', get_te
我正在尝试使用以下命令加载一个名为 Accordion.js 的脚本: function accordion() { wp_register_script( 'accordio
我遇到两种类型的错误,但我不知道如何修复。 您可以在此处查看错误:http://www.brainbuzzmedia.com/themes/vertex/ 第一种类型出现两次,如下所示: Notice
我的网站正在加载 css 文件而不是 js。我的 header.php : // 和我的 functions.php : 我想禁用 wordpress 的 j
我是一名优秀的程序员,十分优秀!