WordPress技巧:如何替换 Gravatar 头像的服务器地址

作者:30115776@qq.com

WordPress默认头像是使用Gravatar头像,而Gravatar头像服务在国内访问又不是很稳定,经常出现无法打开的情况,这样的话用户头像就可能会无法载入,本文介绍使用 Gravatar头像稳定服务器的方法。

解决思路

Gravatar头像无法稳定访问的原因不是Gravatar网站服务器的原因,是国内防火墙的问题,所以解决思路是使用Gravatar头像服务的(HTTPS)加密线路。

实现方法

把代码添加到主题目录下的functions.php文件最后即可 [cc lang=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”php\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”] function fox_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; } add_filter(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’get_avatar\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’fox_get_https_avatar\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’); [/cc]

发表评论