This WordPress snippet will show you how to easily add a new custom default Gravatar / Avatar to your WordPress users profiles to replace the standard user Gravatar. By adding some code to your themes functions.php and creating a new avatar image 60px by 60px you can add your custom Gravatar to the selection of default avatars in the WordPress Admin > Reading section.
Screenshot of default Gravatar options
Firstly you will want to create a new custom Gravatar / Avatar that will be used as your new default avatar for users. This image should be ideally 60px wide and 60px high and for ease save it in PNG format and name it custom-avatar.png.
Once created upload this image to your /wp-content/themes/yourtheme-name/images folder.
Open you themes functions.php file then copy the code below and paste it into the functions file, once completed save the file.
if ( !function_exists('custom_gravatars') ) { function custom_gravatars( $avatar_defaults ) { $myavatar = get_template_directory_uri() . '/images/custom-avatar.png'; $avatar_defaults[$myavatar] = 'people'; return $avatar_defaults; } add_filter( 'avatar_defaults', 'custom_gravatars' ); }
When you now go to your WordPress Admin > Reading section you should see and be able to select your newly uploaded custom Gravatar / avatar to be used across your site for users that do not have a Gravatar account.
Leave a Reply
You must be logged in to post a comment.