WordPress禁用gravatar 头像本地化加速
2018-11-02 来源:学做网站论坛
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;
/**
* 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插件,就实现了预期的效果。
相关知识:wordpress判断用户等级来显示不同的评论头像
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
最新资讯
热门推荐