Replace Gravatar Server with Duoshuo to Fix Slow Gravatar Loading in WordPress
In recent years, Gravatar servers have become increasingly slow or even completely unreachable in some parts of mainland China. Since WordPress uses Gravatar as the default avatar source for its comment system, this can cause both the admin dashboard and post pages to load very slowly.
While disabling avatars in the WordPress admin panel can alleviate the problem, doing so can make your comment section look plain and unattractive. Fortunately, there’s a simple solution—just filter the avatar output and replace the default Gravatar domain with a faster alternative, such as the one provided by Duoshuo (gravatar.duoshuo.com), which is often more accessible in China.
How to Replace the Gravatar Domain in WordPress
To implement this fix, simply add the following code snippet to your theme’s functions.php
file:
function wizhi_get_avatar($avatar) {
$avatar = str_replace(
array("www.gravatar.com", "0.gravatar.com", "1.gravatar.com", "2.gravatar.com"),
"gravatar.duoshuo.com",
$avatar
);
return $avatar;
}
add_filter('get_avatar', 'wizhi_get_avatar', 10, 3);
This code searches for all the standard Gravatar domain names and replaces them with gravatar.duoshuo.com
, effectively rerouting avatar requests through a faster mirror.
Testing the Result
After adding the code, open a blog post with comments and avatars. You should notice a significant speed improvement in how quickly avatars load. This small tweak can dramatically enhance the user experience on your site, especially for visitors located in regions where Gravatar is slow or blocked.
Conclusion
Gravatar loading issues in WordPress can cause frustrating delays, particularly for users in China. Instead of disabling avatars entirely, which hurts the visual layout of your comment section, you can solve the problem by redirecting avatar requests to a more accessible mirror like Duoshuo. With just a few lines of code, your website can retain its design appeal while improving loading performance.