Wordpress替换Gravatar头像默认服务器
1、利用多说Gravatar头像中转服务器替代头像默认服务器。将下面代码添加到当前主题functions.php文件中:functionmytheme_get_avatar($avatar){$avatar=preg_replace("/http:\/\/(www|\d).gravatar.com/","http://gravatar.duoshuo.com",$avatar);return$avatar;}add_filter('get_avatar','mytheme_get_avatar');可惜多说服务稳定性欠佳,有时也会暂时无法显示头像。如编辑已发表的文章,并且文章已有评论,还需要在文章编辑页面打开右上的“显示选项”去掉“评论”勾选,否则在点击更新文章按钮后,还是会向Gravatar头像服务器发送获取头像请求,从而影响页面加载速度。
2、使用https方式(SSL)调用Gravatar头服务器地址使用方法同上,将下面代码添加到主题functions.php文件中:functi泠贾高框onget_ssl_avatar($avatar){$avatar=preg_replace('/.*\/avatar\/(.*)\?s=([\d]+)&.*/','<imgsrc="https://secure.gravatar.com/avatar/$1?s=$2"class="avataravatar-$2"height="$2"width="$2">',$avatar);return$avatar;}add_filter('get_avatar','get_ssl_avatar');貌似添加以上代码后,一些头像缓存插件也将失效。
3、使用Gravatar Fixed 头像修正插件插件设置页面,将Gravatar 服务器和Gravatar SSL 服务器,全部改为:https://secure.gravatar.com插件下载页面http://wpceo.com/gravatar-fixed/
4、另一个比较笨的方法:打开wordpress程序根目录的wp-includes文件夹,找到pluggable.php打开,将大约2150至2157行:if(is_ssl()){$host='https://secure.gravatar.com';}else{if(!emptyempty($email))$host=sprintf("http://%d.gravatar.com",(hexdec($email_hash[0])%2));else$host='http://0.gravatar.com';}替换为:$host='https://secure.gravatar.com';之所以说“笨”是因为下次更新程序,还需要再次修改,不过这个方法最实用。