How to Add New Default Avatar to WordPress

How to Add New Default Avatar to WordPress

If you find yourself in a situation where you need to add a new default avatar to the WordPress system, it is relatively easy. Adding a new function to the functions.php file and hooking it into the avatar_defaults filter, gets it done. It is not recommended to modify the functions.php file directly if you are working with a downloaded theme (purchased or otherwise). Modifications to a downloaded theme file will get overwritten the next time you do an update. From a security perspective, you want to keep up with updates to keep your site current and secure. Best practice is to create a child theme (which will be covered in a future post) and add the function to your child’s functions.php file.

The code is simple. The value specified for AvatarName is the name displayed beside your new avatar image in wp-admin->Settings->Discussion. This is where the “Mystery Person” text appears. The assumption made in the code below is that you are working with a child theme and get_stylesheet_directory_uri() returns the directory of the current child theme.

Make sure to upload the avatar image (default-avatar.png) to the images subfolder of your child theme.

add_filter(‘avatar_defaults’, ‘mynewgravatar’);

function mynewgravatar($avatar_defaults) {
    $insertavatar = get_stylesheet_directory_uri().’/images/default-avatar.png’;
    $avatar_defaults[$insertavatar] = “AvatarName”;
    return $avatar_defaults;

Before the new avatar appears on the front end of your site, you must update the “Default Avatar” setting in the WordPress admin: wp-admin->Settings->Discussion->Default Avatar.

Talk soon…

Drake Moore

Leave a Reply

Your email address will not be published. Required fields are marked *