首页 > 教程
wordpress不使用插件解决网站加载慢和头像不显示
- 2025-11-17
- 1858 ℃
WordPress安装完成后,网站打开时,显示一直打转(加载慢),而且管理员用户头像引入错误。原因是WP加载了谷歌字体和国外的gravatar.com上的用户头像,理所当然被“墙”隔开了,导致网站加载慢,图片引入失败。
解决的办法是禁用谷歌字体,并把头像设置成国内网站的图片(或本地图片)。
给WordPress换一个主题(默认主题下更改functions.php会报错),然后找到/wp-content/主题目录/functions.php,在最后面,加上代码如下:
class Disable_Google_Fonts{
public function __construct(){
add_filter('gettext_with_context',array($this,'disable_open_sans'),888,4);
}
public function disable_open_sans($translations,$text,$context,$domain ){
if ('Open Sans font: on or off' == $context && 'on' == $text){
$translations = 'off';
}
return $translations;
}
}
$disable_google_fonts = new Disable_Google_Fonts;
function dmeng_get_https_avatar($avatar) {
//~ 替换为 https 的域名
$avatar = str_replace(array("www.gravatar.com", "0.gravatar.com", "1.gravatar.com", "2.gravatar.com"), "secure.gravatar.com", $avatar);
//~ 替换为 https 协议
$avatar = str_replace("http://", "https://", $avatar);
return $avatar;
// return '<img alt="" src="http://avatar.csdn.net/4/E/A/3_misakaqunianxiatian.jpg" class="avatar avatar-26 photo" >';
}
add_filter('get_avatar', 'dmeng_get_https_avatar');第二个函数是用来替换头像的,return $avatar则是替换为secure.gravatar.com的默认头像,注释掉的return那一行,是引入自定义的图片路径。
相关内容
移动硬盘打不开千万别格式化
为什么你家装的千兆网还...
批量重命名文件,怎样快...
JQUERY判断一个元素是否...
php提高性能的几个小技巧
推荐39个让你效率提高200...
有没有好用的清理手机垃...
手撸call apply bind
-
很上档次别具一格的代码注释方式
2025-04-07 1276
-
查对象手机必备的一招:新消息从已读变未读
2021-08-07 841
-
语音转文字,文字转语音,两极互转
2025-03-10 1286
-
mac 80个使用技巧合集
2025-08-24 1278
-
网页HTML特殊字符编码对照表
2021-04-13 910
-
测试了一堆远程控制工具,发现最好用的原来是它
2025-04-27 1229
-
从c++魔板算法开始研究加密算法的基础
2025-04-08 1091
-
Vue3 + Vite + Vue Router 4后端返回路由配置动态路由权限管理
2025-04-07 1164
-
微信边写边译和外国人沟通非常高效
2025-06-22 1064
-
国外网站怎么进入
2024-05-07 2267
文章评论 (0)
- 这篇文章还没有收到评论,赶紧来抢沙发吧~


进入有缘空间
点击分享文章