• 设为首页
  • 收藏本站
  • 积分充值
  • VIP赞助
  • 手机版
  • 微博
  • 微信
    微信公众号 添加方式:
    1:搜索微信号(888888
    2:扫描左侧二维码
  • 快捷导航
    福建二哥 门户 查看主题

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

    发布者: 涵韵 | 发布时间: 2025-6-19 09:24| 查看数: 76| 评论数: 0|帖子模式

    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插件,就实现了预期的效果。
    来源:https://zhuji.jb51.net/wordpress/7689.html
    免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

    最新评论

    QQ Archiver 手机版 小黑屋 福建二哥 ( 闽ICP备2022004717号|闽公网安备35052402000345号 )

    Powered by Discuz! X3.5 © 2001-2023

    快速回复 返回顶部 返回列表