配置wordpress:解决头像不显示问题(wordpress 6.2)
一,默认头像效果:
Gavatar的头像在国内不能正常访问,如图:

二,设置:
把以下php代码添加到模板函数funtions.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,从后台添加代码

添加完代码,后 更新文件 按钮保存

设置完之后,头像已可正常显示
说明:刘宏缔的架构森林是一个专注架构的博客,
网站:https://blog.imgtouch.com
原文: https://blog.imgtouch.com/index.php/2023/06/06/pei-zhi-wordpress-jie-jue-tou-xiang-bu-xian-shi-wen-ti/
对应的源码可以访问这里获取: https://github.com/liuhongdi/
或: https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com
三,测试效果

可以看到头像都已可以正常显示
四,查看wordpress的版本:
