Age of Article Warning:
This article was originally published 47 months ago. The tips and techniques explained may be outdated, or information may longer be applicable. Please consider this when viewing the below content.

Gravatar images are wonderful as they make the comments section of our websites look so much better when you can see someone’s face, icon, logo or image. If you don’t know what a Gravatar is then head on over to en.gravatar.com/

What if your commenters don’t have gravatar images- how do you change the image to look good on your website?
change default gravatar opencart
Well recently, a website that I was working on had installed on it a module for blogging in Opencart known as OPExtensions Blog System Opencart, and the developer of this module has configured the comments to pull in the Gravatar, in a similar fashion to the way WordPress pulls in the Gravatar when people comment.

Problem is that many people who are commenting on the blog articles, use email addresses that aren’t registered with Gravatar, and so there’s an ugly blue icon that shows up as a default.

Best way to fix or make changes on Opencart is to use VQMOD XML files to make changes on the fly– if you want to find out more about VQMOD then check out my article–> What is VQMOD

Change default gravatar image in Opencart with VQMOD

So here’s some bonus VQMOD file for you below- make sure to save the file as .xml and upload to your VQMOD > XML folder. Remember this file will only work with the OPExtensions blog module- if you are using another, you will need to make the necessary changes for your files.

Replace “http://www.YOURSITE.COM/IMAGE-FOLDER/NEW-DEFAULT-GRAVATAR.JPG” with the URL to your new default gravatar image

[xml]
<!–For OPExtensions Blog System Opencart //–>
<modification>
<id><![CDATA[change default gravatar in opencart opextensions blog comments]]></id>
<version><![CDATA[1.0.1]]></version>
<vqmver><![CDATA[2.2.1]]></vqmver>
<author><![CDATA[davidtiong.com]]></author>
<file name="catalog/controller/opextensions/comment.php">
<operation>
<search position="replace" offset="6"><![CDATA[private function getAvatar($type,$email = ”){]]></search>
<add><![CDATA[private function getAvatar($type,$email = ”){
$config = $this->config->get(‘blog_comment’);
$default="http://www.YOURSITE.COM/IMAGE-FOLDER/NEW-DEFAULT-GRAVATAR.JPG";
switch($type){
case ‘gravatar’ :
$img = ‘<img src="http://www.gravatar.com/avatar.php?gravatar_id=’.md5(strtolower(trim($email))).’&default=’.urlencode($default).’&rating=PG" width="’.(int)$config[‘avatar_w’].’px" height="’.(int)$config[‘avatar_h’].’px" />’;
break;
}
]]></add>
</operation>
</file>
</modification>
[/xml]

and if you are using the OPExtensions Blog System Opencart you may want to fix the spelling mistake “Creat by” to “Created by” or even change it to “Comment by”…

[xml]
<!– text fix for OPExtensions Blog System Opencart //–>
<modification>
<id><![CDATA[change creat to create in opextensions blog comments fix]]></id>
<version><![CDATA[1.0.1]]></version>
<vqmver><![CDATA[2.2.1]]></vqmver>
<author><![CDATA[davidtiong.com]]></author>
<file name="catalog/language/english/opextensions/comment.php">
<operation>
<search position="replace"><![CDATA[$_[‘text_creatby’] = ‘Creat By ‘;]]></search>
<add><![CDATA[$_[‘text_creatby’] = ‘Created By ‘;]]></add>
</operation>
</file>
</modification>
[/xml]

Change default gravatar image in Opencart with VQMOD was last modified: February 12th, 2013 by David Tiong
Change default gravatar image in Opencart with VQMOD