当前位置: 首页 > WP教程 > 正文

直接从www.gravatar.com主站加载头像

收藏文章Loading
收藏
(95)

www.gravatar.com主站

近日,Gravatar网站CND(内容分发网络)未知原因出现问题,国内无法显示以0.gravatar.com和1.gravatar.com为前缀的头像,而以www.gravatar.com为前缀的却可以,如果你启用了头像缓存插件或主题具备头像缓存功能,空间主机又在国外,不会受到影响,而国内主机则无法实现头像缓存,这一问题严重拖慢了页面打开速度。
可能有人会问,为什么有的站点的Gravatar头像地址是以www.gravatar.com开头,有的却是以0.gravatar.com和1.gravatar.com为前缀呢?WordPress 从2.5版开始集成了Gravatar头像功能,随着使用Gravatar头像的用户越来越多,为了减轻服务器负担,Gravatar网站采用CDN(内容分发网络),就近从Gravatar网站服务器加载头像,提高页面打开速度。正因为如此从WordPress 3.0开始,改进源代码适应CDN,提高头像加载速度。默认情况下还在使用老版本WordPress的用户,由于没有启用CDN功能,所以前缀是www.gravatar.com,直接从主站加载头像,不会受到影响。

下面就说说如何修改WordPress源文件,直接从www.gravatar.com加载Gravatar头像。打开WordPress程序wp-includes目录中的pluggable.php,搜索到下面的代码

if ( !empty($email) )
    $host = sprintf( "http://%d.gravatar.com", ( hexdec( $email_hash[0] ) % 2 ) );
else
    $host = 'http://0.gravatar.com';

替换成一下代码

if ( !empty($email) )
    $host = sprintf( "http://www.gravatar.com", ( hexdec( $email_hash[0] ) % 2 ) );
else
    $host = 'http://www.gravatar.com';

完成保存后覆盖原文件即可。再打开调用Gravatar头像的页面查看源文件,头像全部是以www.gravatar.com开头了,这样就不会加载不出头像影响站点啊的访问速度。

本文固定链接: http://www.csyor.com/532.html - 穿梭于偶然

该日志由 Csyor 于2014年02月06日发表在 WP教程 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: 直接从www.gravatar.com主站加载头像 - 穿梭于偶然
关键字: , , ,

直接从www.gravatar.com主站加载头像:目前有6 条留言

  1. This website is known as a stroll-through for all of the data you needed about this and didn抰 know who to ask. Glimpse here, and you抣l positively discover it.

    2020-10-17 05:30 [回复]
  2. It抯 laborious to find educated folks on this subject, however you sound like you realize what you抮e speaking about! Thanks

    2020-10-07 09:13 [回复]
  3. 地板
    kd13:

    There are certainly a number of particulars like that to take into consideration. That could be a great level to carry up. I provide the thoughts above as general inspiration but clearly there are questions just like the one you convey up the place an important thing can be working in sincere good faith. I don?t know if greatest practices have emerged round issues like that, but I am certain that your job is clearly identified as a good game. Both girls and boys really feel the influence of only a second抯 pleasure, for the remainder of their lives.

    2020-10-05 18:10 [回复]
  4. 板凳
    kd 12:

    This website is really a stroll-by means of for all of the data you needed about this and didn抰 know who to ask. Glimpse here, and also you抣l definitely uncover it.

    2020-10-03 06:49 [回复]
  5. 沙发
    a bathing ape:

    It抯 hard to find knowledgeable individuals on this subject, but you sound like you know what you抮e talking about! Thanks

    2020-09-29 07:14 [回复]

发表评论


快捷键:Ctrl+Enter