由于插件的不稳定,改用了本地缓存头像,这样的话右上角的账户头像也可以正常显示
以下方法可以解决海外访问问题,如果要对国内访问问题进行修正,可以使用插件wp加速,并且启用lazyload
首先我们打开主题下的functions.php
通过百度,找到了以下代码
// HackGravatatr
function wpyou_get_ssl_avatar(avatar) {avatar = preg_replace('/.*\/avatar\/(.*)\?s=([\d]+)&.*/','<img src="https://cdn.v2ex.com/gravatar/1?s=2" class="avatar avatar-2" height="2" width="2">',avatar);
return $avatar;
}
add_filter('get_avatar', 'wpyou_get_ssl_avatar');
原理是使用https方式(SSL)调用Gravatar头像服务器地址,从而绕过对墙问题,白猫大大使用的Gravatar_cn也是绕过墙的问题,但可能是出了些问题或是lazyload出了问题
将上述代码插入到functions中
然后通过搜索gravatar或是在line 560左右找到
/*
* Gravatar头像使用中国服务器
*/
function gravatar_cn( url ){gravatar_url = array('0.gravatar.com','1.gravatar.com','2.gravatar.com','secure.gravatar.com');
return str_replace( gravatar_url, 'gravatar.shino.cc',url );
}
add_filter( 'get_avatar_url', 'gravatar_cn', 4 );.
/*
* 自定义默认头像
*/
add_filter( 'avatar_defaults', 'mytheme_default_avatar' );
function mytheme_default_avatar ( avatar_defaults ) {
//new_avatar_url = get_template_directory_uri() . '/images/default_avatar.png';
new_avatar_url = 'https://cn.gravatar.com/avatar/b745710ae6b0ce9dfb13f5b7c0956be1';avatar_defaults[new_avatar_url] = 'Default Avatar';
returnavatar_defaults;
}
将其注释掉
最后通过搜索https://jsdelivr.amogu.cn/gh/moezx/cdn@3.0.1/img/svg/loader/index.ajax-spinner-preloader.svg
或是在line 362找到以COMMENT FORMATTING注释开头的代码
按照注释中说的,将其替换为,也就是不进行延时
/**
* COMMENT FORMATTING
*
* 标准的 lazyload 输出头像
* <?php echo str_replace( 'src=', 'src="https://jsdelivr.amogu.cn/gh/moezx/cdn@3.0.1/img/svg/loader/index.ajax-spinner-preloader.svg" onerror="imgError(this,1)" data-src=', get_avatar( comment->comment_author_email, '80', '', get_comment_author(), array( 'class' => array( 'lazyload' ) ) ) ); ?>
*
* 如果不延时是这样的
* <?php echo get_avatar(comment->comment_author_email, '80', '', get_comment_author() ); ?>
*
*/
if(!function_exists('akina_comment_format')){
function akina_comment_format(comment,args, depth){GLOBALS['comment'] = comment;
?>
<li <?php comment_class(); ?> id="comment-<?php echo esc_attr(comment_ID()); ?>">
<div class="contents">
<div class="comment-arrow">
<div class="main shadow">
<div class="profile">
<a href="<?php comment_author_url(); ?>" target="_blank" rel="nofollow"><?php echo get_avatar(comment->comment_author_email, '80', '', get_comment_author() ); ?></a>
</div>
<div class="commentinfo">
<section class="commeta">
<div class="left">
<h4 class="author"><a href="<?php comment_author_url(); ?>" target="_blank" rel="nofollow"><?php echo get_avatar( comment->comment_author_email, '24', '', get_comment_author() ); ?><span class="bb-comment isauthor" title="中央钦定的<?php #esc_attr_e('Author', 'akina'); ?>">博主</span> <?php comment_author(); ?> <?php echo get_author_class(comment->comment_author_email,comment->user_id); ?></a></h4>
</div>
<?php comment_reply_link(array_merge(args, array('depth' => depth, 'max_depth' =>args['max_depth']))); ?>
<div class="right">
<div class="info"><time datetime="<?php comment_date('Y-m-d'); ?>"><?php echo poi_time_since(strtotime(comment->comment_date_gmt), true );//comment_date(get_option('date_format')); ?></time><?php echo siren_get_useragent(comment->comment_agent); ?><?php echo mobile_get_useragent_icon(comment->comment_agent); ?> 来自: <?php echo convertip(get_comment_author_ip()); ?>
<?php if (current_user_can('manage_options') and (wp_is_mobile() == false) ) {comment_ID = comment->comment_ID;i_private = get_comment_meta(comment_ID, '_private', true);flag .= ' <i class="fa fa-snowflake-o" aria-hidden="true"></i> 状态: <a href="javascript:;" data-actionp="set_private" data-idp="' . get_comment_id() . '" id="sp" class="sm" style="color:rgba(0,0,0,.35)">私密(<span class="has_set_private">';
if (!empty(i_private)) {flag .= '是 <i class="fa fa-lock" aria-hidden="true"></i>';
} else {
flag .= '否 <i class="fa fa-unlock" aria-hidden="true"></i>';
}flag .= '</span>)</a>';
flag .= edit_comment_link(__('<i class="fa fa-pencil-square-o" aria-hidden="true"></i> 编辑'), '<span>', '</span>');
echoflag;
} ?></div>
</div>
</section>
</div>
<div class="body">
<?php comment_text(); ?>
</div>
</div>
<div class="arrow-left"></div>
</div>
</div>
<hr>
<?php
}
}
上面这个{1}是显示问题,不存在
大功告成
如果有更简便的方法可以进行分享
Comments NOTHING