我喜欢的人头像显示在我的博客评论谁. WordPress的支持的gravatar服务本身因此启用,这是很容易. 然而,它是有代价 - 从另一个域访问外部文件中增加了许多额外的加载时间的新形式 DNS 查找, 新 SSL 连接使, 等等. Would­n’t it be nice to have gravatars stored loc­ally and served from your own serv­er. 嗯,这就是我一直在做了一段时间, 如果你想知道如何, 阅读...

In case you’re still won­der­ing just why you’d want to do this, let me offer a few more bene­fits — images served loc­ally can be com­pressed before serving them, for example ‑all my images are con­ver­ted into webp ver­sions, and any browser which sup­ports webp gets the webp ver­sion. This is in addi­tion to the reduc­tion from not hav­ing to con­nect to an extern­al serv­er. The loc­al resources can also have a cach­ing head­er set on them so that browsers will cache them. Gravatar does­n’t provide for a very long cache time.

I have cre­ated 3 cus­tom func­tions, 我只是把我的主题的functions.php文件. The first is a cus­tom fil­ter for the nat­ive word­press get_avatar(). 从的gravatar和谷歌的第二争夺化身呼吁时, and the third cre­ates a daily cronjob which refreshes the gravatars — in case they’ve been changed, or a pre­vi­ously unavail­able one is now avail­able.

You will need to do a little bit of tinker­ing to make it com­pat­ible with your theme — I use the “bones” frame­work as you’ll notice in the 3RD func­tion I’ve reused some code that it provided. You will also need to cre­ate, or cus­tom­ise the path to store the gravatars, which in my case are stored in the theme folder in the sub­path “/library/images/gravatars/”

认为我们已经错过了什么? 让我们通过下面的评论知道. 如果您想订阅,请使用菜单上的订阅链接右上方. 您还可以通过使用下面的链接社会分享这与你的朋友. 干杯.