让WordPress头像Gravatar启用HTTPS

WordPress使用的头像服务是来自Gravatar,默认不是https链接形式,加载很慢,甚至无法访问。

A Globally Recognized Avatar
A Globally Recognized Avatar

什么是Gravatar

Gravatar是一图像跟随著您到访过的网站,当您在博客中留言或发表文章,它将会出现在您的名称旁。头像协助识别您在博客和论坛发表的文章,何乐而不为呢?

Gravatar非https的情况下,国内经常由于某些原因(你懂的)无法访问,如果启用了https,即可直接访问图片,加载也就变快了

在你的WordPress主题functions.php中加入:

function iopenv_get_https_avatar($avatar) {
	// Replacement for HTTPS domain
	$avatar = str_replace(array("www.gravatar.com", "0.gravatar.com", "1.gravatar.com", "2.gravatar.com"), "secure.gravatar.com", $avatar);
	// Replacement for HTTPS protocol
	$avatar = str_replace("http:", "https:", $avatar);
	return $avatar;
}

add_filter('get_avatar', 'iopenv_get_https_avatar');

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注