WordPress:在网站上仅加载一个jquery脚本 [英] Wordpress: Load only one jquery script on website

查看:67
本文介绍了WordPress:在网站上仅加载一个jquery脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚要启动一个WordPress网站,但注意到它当前正在加载两个jquery文件,一个包含在wp-includes中,另一个来自我的header.php中,是否可以使wordpress将wp-include包含在其中.前端?做了大量的搜索,并且对此的唯一提及似乎包括以下代码,但是我找不到有关它的任何文档,任何想法?

Just about to launch a WordPress site but have noticed that it's currently loading in two jquery files, one in wp-includes and one from my header.php, is there a way to make wordpress load the wp-include one on the front end? Done quite a bit of search and have the only mention of this seems to include the following code, but I can't find any documentation about it, any ideas?

<?php wp_enqueue_script("jquery"); ?>

推荐答案

从WordPress 3.3开始,这是使用适当钩子的最佳方法:

As of WordPress 3.3, this is the best way to do it, using the proper hook:

if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
    wp_deregister_script('jquery');
    wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null);
    wp_enqueue_script('jquery');
}

这篇关于WordPress:在网站上仅加载一个jquery脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆