WordPress使用Cravatar解决Gravatar头像无法访问的问题

前言

在wordpress中评论去的头像2021年2月到现在一直是无法加载的,我大中华Gril Friend Wall天下无敌

好在我们有了Cravatar,Cravatar兼容Gravatar的头像API,经过三级匹配(Cravatar头像->Gravatar头像->QQ头像),基本可以得到准确头像,除非QQ号有误。

使用Cravatar有两种办法:

1.使用WP-China-Yes插件

这种方式我不推荐用,需要的话可以找我索要插件

图片[1]-WordPress使用Cravatar解决Gravatar头像无法访问的问题-阿张同学

2.你可以将以下代码加入你的主题的functions.php文件或您的插件中即可启用(推荐)

if ( ! function_exists( 'get_cravatar_url' ) ) {
    /**
     *替换Gravatar头像为Cravatar头像
     *
     * @param string $url
     *
     * @return string
     */
    function get_cravatar_url( $url ) {
        $sources = array(
            'www.gravatar.com',
            '0.gravatar.com',
            '1.gravatar.com',
            '2.gravatar.com',
            'secure.gravatar.com',
            'cn.gravatar.com'
        );
        return str_replace( $sources, 'cravatar.cn', $url );
    }
    add_filter( 'um_user_avatar_url_filter', 'get_cravatar_url', 1 );
    add_filter( 'bp_gravatar_url', 'get_cravatar_url', 1 );
    add_filter( 'get_avatar_url', 'get_cravatar_url', 1 );
}
图片[2]-WordPress使用Cravatar解决Gravatar头像无法访问的问题-阿张同学
插入位置展示

替换默认头像设置的Gravatar名称

图片[3]-WordPress使用Cravatar解决Gravatar头像无法访问的问题-阿张同学

最后,就如同我的评论区一样可以显示头像啦

本文学习自wordpress大学

© 版权声明
THE END
喜欢就支持一下吧
点赞3赞赏 分享
评论 抢沙发
头像
拿起笔,写下你的梦想,你的人生就从此刻起航
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容