玉惠 發表於 2023-9-26 00:00:00

禁用wordpress gravatar使用本地头像提高网页打开速度

<span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>WordPress默认的头像是读取gravatar.com上的图片的,对于国内用户来说会使网页打开速度变慢。所以我决定删除掉这块功能。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>修改get_avatar函数,在wp-includes/pluggable.php内。修改后的函数如下: </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span>
</div>
代码如下:</div>
<div id="phpcode33" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
if ( !function_exists( 'get_avatar' ) ) : <br>
/** <br>
* Retrieve the avatar for a user who provided a user ID or email address. <br>
* <br>
* @since 2.5 <br>
* @param int|string|object $id_or_email A user ID, email address, or comment object <br>
* @param int $size Size of the avatar image <br>
* @param string $default URL to a default image to use if no avatar is available <br>
* @param string $alt Alternate text to use in image tag. Defaults to blank <br>
* @return string tag for the user's avatar <br>
*/ <br>
function get_avatar( $id_or_email, $size = '96', $default = '', $alt = false ) { <br>
if ( ! get_option('show_avatars') ) <br>
return false; <br>
if ( false === $alt) <br>
$safe_alt = ''; <br>
else <br>
$safe_alt = esc_attr( $alt ); <br>
if ( !is_numeric($size) ) <br>
$size = '96'; <br>
$default = includes_url('images/blank.gif'); <br>
$avatar = ""; <br>
return apply_filters('get_avatar', $avatar, $id_or_email, $size, $default, $alt); <br>
} <br>
endif; </div>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>即使用该函数,仅可能返回一个默认头像(位于wp-includes/images/blank.gif内),再配合simple local avatars或Add Local Avatar插件,就实现了预期的效果。</span>
頁: [1]
查看完整版本: 禁用wordpress gravatar使用本地头像提高网页打开速度