Depending on time of the day and number of comments, using WordPress gravatars can cause a significant slow-down in your blog load time.
Last week, I noticed a significant slow-down in one of my blogs. Pages were taking about 8-10 seconds to load, when previously they would load almost instantaneously.
There are several ways to address this issue –
1. Turn-off Gravatars
How to turn off gravatars –
- Go to Settings >> Discussion.
- Scroll down to the bottom of the screen to the Avatar section.
- Under Avatar Display select Don’t Show Avatars.
However, turning off gravatars will make your WordPress blog comments section less personalized, and less visually compelling.
2. Set Number of Comments
Another way to deal with slow load-time is to reduce the number of comments shown on each page.
Again go to Settings >> Discussion. The last bullet under Other Comment Settings allows you to set the maximum number of comments shown on each page.
You can also set the order in which the comments are displayed, e.g. display newer or older comments first.
Limiting the number of comments per page, however, will make it less likely for users to read all the comments.
In addition, it may confuse search engines, causing you to lose the keyword value of your comments, or worse, result in duplicate content penalties.
3. Use Your Own Gravatars
Using local gravatar images lets you control the look of your blog, and removes the added time overhead of accessing the gravatar.com site.
To use local gravatar images, add the function below into your theme functions.php file.
function local_gravatar($comment, $dim) { static $gravatar_img = NULL; if (!strcmp($comment->comment_author, "YOUR_USER_ID")) return "<img src='YOUR_IMAGE.JPG'" . "' width='" . $dim . "' height='" . $dim . "' />"; // Return a gravatar image based on IP $img_num = intval($comment->comment_author_IP); if (!$gravatar_img) { $gravatar_img = get_gravatar_images(); if (!$gravatar_img) return NULL; $gravatar_img = explode('|', $gravatar_img); } $img_count = count($gravatar_img); $index = abs($img_num % $img_count); // Construct new image http $img_uri = "<img src='" . get_theme_mod('gravatar_dir') . $gravatar_img[$index] . "' width='" . $dim . "' height='" . $dim . "' />"; return $img_uri; }
Lines 3-4 – Checks for your user-ID and returns a special predefined image.
Lines 7-19 – For all other users, we return a local gravatar image based on their IP. You can also return gravatar images based on e-mail or website.
To do this replace $comment->comment_author_IP on Line-7 with $comment->comment_author_email or $comment->comment_author_url.
Note – In Line-9 we call the get_gravatar_images function which retrieves an appropriate image from a list of images in your local blog directory.
Here is the source code for the get_gravatar_images function.
Below are a set of gravatar images I created for my Shiba WordPress theme. Feel free to use them as your initial example gravatar images.
This is an example WordPress blog page with over 100 comments, using the local_gravatar function above.
4. Use a Gravatar Cache Plugin
There are also a variety of plugin-ins that allow you to cache gravatar results locally so that your blog does not need to keep accessing the gravatar.com site.
Here is a list of other great WordPress optimization tips by Vladimir Prelovac.
Craig says
You absolute moron. Gravatar.com is highly tuned to serve avatars and does a better job at it than most people’s piss-ant hosting can. Comment paging is the answer.
ShibaShake says
Perhaps you were too busy to read the article before leaving a comment. In the article I have a whole section on –
This article has page speed tests as well as a detailed explanation of gravatars and page speed.
http://www.seomofo.com/wordpress/comments-slow-page-speed.html
Here is an excerpt from the article –
This article on rude people may also be helpful.
http://shibashake.com/dog/rude-dogs-and-rude-people#rude-people
Roee Yossef says
Love it Shiba !