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 插件,就實現了預期的效果。