The default mystery man is really annoying for most users. Plus if you have one more chance of branding your blog, then why not do it. Changing your default gravatar lets you brand your blog more. With this snippet below you can change your default gravatar.
First you need to open your functions.php which is located in your template folder. If you don’t have one then create one and insert the following code:
1 | add_filter( 'avatar_defaults' , 'newgravatar' ); |
3 | function newgravatar ( $avatar_defaults ) { |
4 | $myavatar = get_bloginfo( 'template_directory' ) . '/images/gravataricon.gif' ; |
5 | $avatar_defaults [ $myavatar ] = "WPBeginner"; |
6 | return $avatar_defaults ; |
In the code the image is being extracted from the theme directory and it is called gravataricon.gif obviously you will change it to your image name. Where it says WPBeginner, that is the name of the avatar of how it will show in your admin panel options area.
Head over to your admin panel and click Settings > Discussion and change the icon, and now you have a branded comment area with your logo.
No comments: