找到你网站名为functions.php的文件,然后添加以下代码:
add_filter('get_avatar', 'qq_img', 10, 2);
function qq_img($avatar,$id_or_email)
{
$email = '';
//获取邮箱
if (is_numeric($id_or_email)){
$id = (int)$id_or_email;
$user = get_userdata($id);
if ($user)
$email = $user->user_email;
}else if(is_object($id_or_email)){
if (!empty($id_or_email->user_id)){
$id = (int)$id_or_email->user_id;
$user = get_userdata($id);
if ($user)
$email = $user->user_email;
}else if(!empty($id_or_email->comment_author_email)){
$email = $id_or_email->comment_author_email;
}
}else{
$email = $id_or_email;
}
$hash = md5(strtolower(trim($email)));
$url = 'https://avatar.zrahh.com/avatar/' . $hash;
if(stripos($email,"@qq.com"))//判断是否为QQ邮箱
{
$qq=str_ireplace("@qq.com","",$email);
if(preg_match("/^\d+$/",$qq))//正则过滤英文邮箱
{
$qqavatar="https://q2.qlogo.cn/headimg_dl?dst_uin=".$qq."&spec=100";
return '<img src="'.$qqavatar.'"class="avatar avatar-50 photo" width="50" height="50" alt="avatar" />';
}else{ //如果是英文QQ邮箱就调用Gravatar头像
return '<img src="'.$url.'"class="avatar avatar-50 photo" width="50" height="50" alt="avatar" />';
}
}else{ //不是QQ邮箱
return '<img src="'.$url.'"class="avatar avatar-50 photo" width="50" height="50" alt="avatar" />';
}
}
现在使用QQ邮箱评论可以显示QQ头像了,但还有几个缺点:
1.会覆盖掉那些设置了Gravatar头像却使用QQ邮箱的用户。网上搜到了一篇利用返回http头判断用户是否设置了头像,但在国内会拖慢加载速度(国内源仍然不快),故没有借鉴,等有空看看有没有更好的方法。
2.自定义Gravatar默认头像失效,这个对我来说不是很重要,所以就不管了(坏笑)
3.未在其他主题测试过,兼容性未知
学习了,感谢

博主这个链接放到哪里啊!
@ 2678937502 进入你的服务器找到你主题模板名为functions.php的文件然后你直接复制我的那些代码,然后粘贴放到里面就好