为wordpress提速,禁用gravatar,使用本地头像
2013-06-08 11:47
246 查看
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插件,就实现了预期的效果。
修改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插件,就实现了预期的效果。
相关文章推荐
- 禁用wordpress gravatar使用本地头像提高网页打开速度
- wordpress 禁用gravatar使用本地头像提高网页打开速度
- WordPress使用技巧(1)-禁用 Gravatar 头像
- 为wordpress添加本地头像功能代替Gravatar
- WordPress中Gravatar头像缓存到本地及相关优化的技巧
- WordPress初级教程-21: Wordpress的Gravatar头像功能使用方法
- 黄聪:wordpress如何使用get_avatar禁止调用gravatar头像,替换为自定义头像
- WordPress全球通用Gravatar头像注册使用教程(小白进)
- WordPress中Gravatar头像缓存到本地及相关优化的技巧
- WordPress评论AJAX实时显示Gravatar头像
- WordPress头像本地缓存优化
- 解决wordpress下的gravatar评论头像不显示问题
- WordPress博客程序因gravatar评论头像打开慢的解决方案
- wordpress博客gravatar头像被墙的解决办法
- 利用Gravatar,拥有自己的全球头像,wordpress评论可用
- iOS在更改用户头像并保存至本地沙盒目录中对于UIImagePickerController、UIAlertController的使用
- 零基础使用xampp与WordPress在本地开发一个简单的网站(OS X Yosemite 10.10.5)
- 提升WordPress的Gravatar头像加载速度方法:缓存本地化国内服务器
- wordpress中替换Gravatar头像默认服务器
- 使用WampServer在本地玩转WordPress