安装wordpress主题后发现评论头像无法显示。因为wordpress程序属于国外,国内屏蔽了Gravatar,这导致国内有的Wordpress网站头像无法显示。如下图头像显示

0.gravatar.com,1.gravatar.com,secure.gravatar.com等网址有时无法访问,导致无法读取头像。可以更换其他Gravatar头像镜像服务器地址。如cn.cravatar.com
以下是解决wordpress头像不能显示的一个方法。在wordpress主题-外观-编辑中,打开functions.php文件,把以下代码复制放到该文件中保存即可。
//评论头像gravatar显示
function get_ssl_avatar($avatar) {
$avatar = preg_replace('/.*\/avatar\/(.*)\?s=([\d]+)&.*/','<img src="http://cn.cravatar.com/avatar/$1?s=$2" class="avatar avatar-$2" height="50" width="50">',$avatar);
return $avatar;
}
add_filter('get_avatar', 'get_ssl_avatar');
解决wordpress仪表盘头像错位
另外,从WordPress4.2开始,仪表盘的“活动”小工具的头像有的会出现撑破现象,如下图:主要是width和height设置问题;将下面的代码添加到主题的functions.php保存即可解决gravatar头像撑破问题。

/**
* WordPress 4.2 修复仪表盘头像错位
* http://www.bokequ.com/310.html
*/
function fixed_activity_widget_avatar_style(){
echo '<style type="text/css">
#activity-widget #the-comment-list .avatar {
position: absolute;
top: 13px;
width: 50px;
height: 50px;
}
</style>';
}
add_action('admin_head', 'fixed_activity_widget_avatar_style' );
以上就是wordpress的评论头像 Gravatar头像打不开解决方法,欢迎交流。


评论