We have been using a WordPress theme for some time without any problem, and changing the site to be using a new one will result on the default gravatar image not showing correctly on the comments.
Find below an example image of the broken gravatar images.
Most of the WordPress themes use the native function get_avatar to display the avatar images of the users that comment our posts. Some WordPress themes have a wrong implementation of the call to get_avatar function and the usage of the functions is not working as intended. Probably the error has been there for ages, but nobody notice it before because the Gravatar server was showing the image, even with the wrong arguments attached to the GET url.
An update to Gravatar made the incorrectly implemented themes to fail, making the user avatar images to show as broken on the comments and impacting negatively to the user experience of our site.
After some research I found out that the solution is to change a few lines of code on your WordPress theme. Here are the steps to follow to fix this problem.
1. Find all the occurrences of the function get_avatar under your WordPress theme folder (on wp-content/themes)
2. Identify the wrong formatted calls
Wrongly used parameter – Example #1
echo get_avatar($comment,$size='48',$default='<path_to_url>' );
Wrongly used parameter – Example #2
echo get_avatar($comment,48,'<path_to_url>' );
3. Change the previously wrong formatted calls. Please note that the number of the second parameter stands for the avatar size, so feel free to change it for the size you actually want.
echo get_avatar( $comment, 48 );
4. Upload the modified files to your theme folder.
5. Optional. If you are using any caching plugins such as W3 Total Cache or WP Super Cache you should purge your page cache in order to spread the changes.
Now we should be able to see the gravatar images showing back normally as in the next picture
Was this article useful? Did it solve your problem? Leave a comment!