By default, WordPress assigns a generic avatar to guest commenters, typically sourced from Gravatar. While this works for many sites, it introduces unnecessary external requests and limits customization. If you want to enhance your website’s branding, improve page speed, and maintain better control over guest avatars, hosting a custom default avatar locally is the best solution. In this guide, you’ll learn how to replace WordPress’s default guest avatar with a custom image using a simple PHP snippet—no plugins required.
Gravatar (Globally Recognized Avatar) is WordPress’s default system for managing user profile pictures across websites. When a user comments on a WordPress site, their email address is matched with their Gravatar profile to display their chosen avatar. If no Gravatar is found, WordPress assigns a default avatar, such as the “Mystery Person” or “Blank” icon, retrieved from secure.gravatar.com. While Gravatar offers convenience, it also introduces external requests that can affect site speed or performance and privacy. Many site owners prefer to host custom avatars locally to maintain control over branding and reduce reliance on third-party services.
How Gravatar Increases HTTP Requests and Slows Down WordPress
Using the default WordPress Gravatar adds extra HTTP requests because each commenter’s avatar is fetched from secure.gravatar.com, creating multiple external requests per page load. On a site like LELB Society, with over 8,300 comments, this can result in hundreds of additional HTTP requests per post, significantly impacting page speed. Each request requires DNS lookups, SSL handshakes, and image retrieval, which increases load times, especially for posts with over 100 comments, such as Latin Phrases in English. By hosting a custom default avatar locally, WordPress can serve guest avatars directly from the same server, reducing external dependencies, speeding up page rendering, and improving overall site performance.
In this section of the article, I’ll guide you through the process of setting a custom avatar for guest comments on your WordPress website, step-by-step. By customizing the avatar, you can create a more personalized and engaging experience for your visitors. From uploading your chosen image to configuring the necessary settings, I’ll cover each stage in detail to ensure your custom avatar is displayed perfectly for guest comments. Let’s get started!
Choosing or editing a custom avatar for your WordPress website is an excellent way to personalize your site and create a memorable impression on your visitors. To ensure your avatar appears sleek and clean on retina displays, the ideal dimensions should be 200×200 pixels. This square dimension is perfect for maintaining visual consistency and avoiding any distortion.
Custom Avatar on LELB Society in 200×200 Pixels and WebP Format
When uploading your custom avatar, it’s important to use appropriate metadata for accessibility and SEO purposes. Title your image as “custom-avatar” and use an alt text like “Custom Avatar for Guest Comments” to provide context for screen readers and search engines. If your server supports it, consider converting your avatar into the WebP format to optimize performance. This format offers superior compression, which can speed up your site’s load times. Once you’ve prepared your image, upload it to your media library and copy the URL of the custom-avatar for use throughout your site. By following these steps, you’ll ensure your custom avatar enhances both the aesthetics and functionality of your WordPress website.
10 Proven Ways to Speed Up Your WordPress Site Effectively with a video tutorial
In addition, your custom avatar image should be compressed to ensure maximum website speed, especially if it is frequently loaded on sites with many comments, such as those left by guest commenters. To optimize performance and reduce loading times, it’s crucial that the image size does not exceed 10 KB. This compression minimizes the impact on your site’s bandwidth and enhances the overall user experience by maintaining swift and responsive page loads, even with high comment activity.
To replace WordPress’s default Gravatar with a locally hosted custom avatar for guest commenters, add the following PHP code snippet to your theme’s `functions.php` file. In the following PHP code, be sure to replace the placeholder URL with the actual URL of the custom avatar image that you previously uploaded to your media library. This ensures that your WordPress site will correctly reference and display your custom avatar. By updating the URL in the code, you personalize the avatar displayed for guest comments or users without their own profile picture. Here’s an example of how your code should look:
add_filter('get_avatar', function($avatar, $id_or_email, $size, $default, $alt) {
$custom_avatar_url = 'https://yourwebsite.com/wp-content/uploads/your-custom-avatar.jpg'; // Replace this with the actual URL of your custom avatar image
if (strpos($avatar, 'gravatar.com') !== false || strpos($default, 'gravatar.com') !== false) {
$avatar = "<img alt='{$alt}' src='{$custom_avatar_url}' class='avataravatar-{$size} photo' height='{$size}' width='{$size}' />";
}
return $avatar;
}, 10, 5);
This code ensures that guest commenters are assigned a custom avatar stored on your website instead of the default Gravatar image, reducing external requests and improving site performance. Logged-in users with a Gravatar will still see their profile picture as usual. After adding the snippet, clear your WordPress and CDN cache to see the changes in action.
Change Discussion Settings in WordPress Dashboard Area
How to Set a Custom Avatar in WordPress Dashboard Area, Settings, Discussion
Now that you’ve added the PHP code, the next step is to navigate to your WordPress dashboard. From there, go to the “Settings” menu and click on “Discussion.” Scroll down to the “Default Avatar” section, where you will see various options for the default avatar. Select the “Custom Avatar” option from the list. This will ensure that your custom avatar is used for guest comments. Once you’ve made your selection, don’t forget to hit the “Save Changes” button at the bottom of the page to apply the new settings. Your WordPress site will now display the custom avatar you uploaded for guest comments, providing a personalized touch for your visitors.
Minimizing Plugin Usage for Optimal Performance
How to create a WordPress membership site without plugin
There are probably a multitude of WordPress plugins that could achieve this function. However, at LELB Society, a large educational membership website with 4,500 posts and 8,300 comments, we limit our use to only six plugins. This approach is intentional because installing numerous plugins for each individual function is not recommended and can lead to performance issues, increased security vulnerabilities, and potential conflicts. By carefully selecting and minimizing plugin usage, we maintain optimal site performance and reliability, ensuring a smooth experience for our users.
The Overlooked Power of Custom Avatars in WordPress
WordPress is the most popular content management system (CMS) in the world, powering more than 40% of all websites. The platform’s popularity means that a significant portion of its users and commenters are logged-out users. Consequently, the default Gravatar, such as the dull and clichéd Mystery Person, is frequently overused across countless websites. This widespread use of the default avatar leads to a lack of personalization and uniqueness in comment sections, making user interactions feel impersonal and monotonous.
Leave voice and text comments at LELB Society to learn asynchronously
It’s puzzling why many prestigious websites on WordPress haven’t adopted the practice of setting custom avatars, given the simple steps involved in doing so. Custom avatars not only enhance the visual appeal of a site but also contribute to a more engaging and memorable user experience. By replacing the generic Gravatar with a unique image, websites can reinforce their brand identity and foster a sense of community among their visitors. Despite the clear benefits, it seems that the convenience of sticking with the default settings often outweighs the effort required to implement custom avatars. It’s time for more WordPress sites to realize the potential of this small yet impactful customization.
The Importance of Avatars for Social Presence on LELB Society
Best Comment Box UI practices for a better UX in your website visitors to realize a sense of social presence
By keeping avatars enabled, LELB Society maintains a dynamic and interactive environment where contributors feel recognized and valued. Profile pictures personalize discussions, making online interactions more relatable and engaging. Instead of removing avatars, optimizing them—such as hosting default guest avatars locally—ensures a balance between social presence, branding, and website performance.
To test how custom avatars appear on LELB Society, simply scroll down to the comment box below and locate the avatar image associated with a guest comment. You can right-click on the image and select “Copy image address” to view the URL. This will reveal that the custom avatar is locally hosted on our server. This method not only ensures a personalized user experience but also improves load times and performance by utilizing our server’s resources. Feel free to experiment with different comments and avatars to see how they integrate seamlessly with the LELB Society platform.
Dr. Mohammad Hossein Hariri Asl is an English and Persian instructor, educator, researcher, inventor, published author, blogger, SEO expert, website developer, entrepreneur, and the creator of LELB Society. He's got a PhD in TEFL (Teaching English as a Foreign Language).
2 thoughts on “Use a Custom Avatar for Guest Comments in WordPress”
This is a sample test comment written by a guest commenter at LELB Society to check the custom avatar for guest commenters without an account at LELB Society.
This is a sample test comment written by a guest commenter at LELB Society to check the custom avatar for guest commenters without an account at LELB Society.
Thanks for leaving a comment as a guest commenter to test our custom avatar.