4 Methods to Accelerate Gravatar Avatars and Improve WordPress Speed
Recently, Gravatar avatars have been blocked in certain regions, causing significant slowdowns for most WordPress blogs. Xiao Z previously shared a tutorial on "Enabling Gravatar Avatar Caching to Solve WordPress Slow Loading," but later realized it was not comprehensive enough. After several days of analysis, this article serves as a summary to help everyone.
Method 1: Using the gravatar-fixed Plugin
The simplest solution is to use the gravatar-fixed plugin to cache Gravatar avatars. Developed by WPCEO, this plugin corrects issues where the Gravatar server cannot be accessed normally and allows you to customize the Gravatar server address. Xiao Z has already enabled the default caching server 0.bsdev.cn, so after installing this plugin, you will feel an immediate speed boost without any additional configuration. This is very suitable for beginners.\n
![]()
Figure 1-1: gravatar-fixed plugin settings
Download: gravatar-fixed.zip
Method 2: Using Xiao Z Blog's Caching Service (Recommended)
After enduring the pain of Gravatar avatars being blocked, Xiao Z Blog used overseas servers to proxy Gravatar avatars and leveraged Qiniu Cloud Storage's acceleration services, providing them for free. To experience the speed boost, simply add the following code to your theme's functions.php file:
// Gravatar cached avatar
function xiaoz_get_avatar($avatar) {
$avatar = str_replace(array("www.gravatar.com","0.gravatar.com","1.gravatar.com","2.gravatar.com"),
"0.bsdev.cn",$avatar);
return $avatar;
}
add_filter( 'get_avatar', 'xiaoz_get_avatar', 10, 3 );
// End of cached avatar
Method 3: Cache to Local Storage (For Overseas Host Users)
In a previous article, Xiao Z shared this method but overlooked an important issue: Gravatar is blocked in China, so domestic hosts cannot cache avatars locally. This method is only suitable for users with overseas hosts. If your overseas host speed is not fast enough, it is recommended to use Method 1 or Method 2.
- Create a folder named
avatarin the website root directory (set permissions to 755 or 777). Some VPS users may need to change the user group towww. - Create a default avatar image named
default.jpgand place it in theavatarfolder. - Add the following code to the
functions.phpfile of your current theme:
function v7v3_avatar($avatar) {
$tmp = strpos($avatar, 'http');
$g = substr($avatar, $tmp, strpos($avatar, "'", $tmp) - $tmp);
$tmp = strpos($g, 'avatar/') + 7;
$f = substr($g, $tmp, strpos($g, "?", $tmp) - $tmp);
$w = get_bloginfo('wpurl');
$e = ABSPATH .'avatar/'. $f .'.jpg';
$t = 1209600; // Set cache time to 14 days, unit is seconds
if ( !is_file($e) || (time() - filemtime($e)) > $t ) { // Update if avatar exceeds set time or does not exist
copy(htmlspecialchars_decode($g), $e);
} else $avatar = strtr($avatar, array($g => $w.'/avatar/'.$f.'.jpg'));
if (filesize($e) < 500) copy($w.'/avatar/default.jpg', $e);
return $avatar;
}
add_filter('get_avatar', 'v7v3_avatar');
Method 4: Disable Avatar Functionality
This approach is somewhat extreme but effective. For users who do not have high requirements and do not want to tinker, you can uncheck the "Show avatars" option in Settings > Discussion in the backend. This will significantly improve speed.

Figure 4-1: Disable avatar display
Currently available caching servers include 0.bsdev.cn (provided by Xiao Z Blog) and cd.v7v3.com (provided by V7V3). Of course, there may be more. The more users use the same caching server, the faster the secondary loading will be.
Special Reminder: If you use Duoshuo (多说), note that Duoshuo has its own caching server. However, for some reason, Duoshuo has recently started redirecting many avatars back to the official source (reports were sent to the official team, but no results were received). Therefore, users of Duoshuo will also experience slow loading, manifested as some avatars failing to load after redirecting back to the source, as shown in the screenshot below. None of the methods above work for users with Duoshuo enabled; you must disable Duoshuo for the solutions to take effect. At this moment, no method has been found to make them coexist (unfortunately, Xiao Z has also switched back to the built-in comments). Please understand.

Duoshuo partial avatar redirect