title
菜鸟吧 首页 站长学堂 WP教程 查看内容

WordPress默认头像是读取gravatar.com上的图片的,怎么才能禁用wordpress使用本地头像

2019-10-15 15:44| 发布者: admin| 查看: 2| 评论: 0|原作者: 菜鸟哥

摘要: 下面为大家分享个为wordpress提速使用本地头像的方法,需要的朋友不要错过WordPress默认的头像是读取gravatar.com上的图片的,对于国内用户来说会使网页打开速度变慢。所以我决定删除…… ...

下面为大家分享个为wordpress提速使用本地头像的方法,需要的朋友不要错过

WordPress默认的头像是读取gravatar.com上的图片的,对于国内用户来说会使网页打开速度变慢。所以我决定删除掉这块功能。

修改get_avatar函数,在wp-includes/pluggable.php内。修改后的函数如下:

代码如下:

if ( !function_exists( 'get_avatar' ) ) :
/**
* Retrieve the avatar for a user who provided a user ID or email address.
*
* @since 2.5
* @param int|string|object $id_or_email A user ID, email address, or comment object
* @param int $size Size of the avatar image
* @param string $default URL to a default image to use if no avatar is available
* @param string $alt Alternate text to use in image tag. Defaults to blank
* @return string tag for the user's avatar
*/
function get_avatar( $id_or_email, $size = '96', $default = '', $alt = false ) {
if ( ! get_option('show_avatars') )
return false;
if ( false === $alt)
$safe_alt = '';
else
$safe_alt = esc_attr( $alt );
if ( !is_numeric($size) )
$size = '96';
$default = includes_url('images/blank.gif');
$avatar = "";
return apply_filters('get_avatar', $avatar, $id_or_email, $size, $default, $alt);
}
endif;

即使用该函数,仅可能返回一个默认头像(位于wp-includes/images/blank.gif内),再配合simple local avatars或Add Local Avatar插件,就实现了预期的效果。

路过

雷人

握手

鲜花

鸡蛋
Archiver 手机版 小黑屋 网站地图

Copyright © 2015-2026 菜鸟吧论坛 |找资源研究学习当然上菜鸟吧论坛

警告:本站所有资源收集世界互联网,请下载后24小时之内删除,否則後果自負!
WARNING: ‌All resources from the web. Delete within 24 hours or consequences at your own risk!
郑重声明:站内所有资源均来自互联网或会员投稿发布, 如果侵犯了权益请联系删除,E-mail:cainiaovip8@qq.com 商用请购买正版。

返回顶部