As shown below, the WordPress default avatar customization has been successfully modified!
The avatar in the above picture is not available by default. It is required. We customize it ourselves!
Friends who are familiar with WordPress should know that in the background - settings - discussion, you can set the default Gravatar avatar, but the icons that come with it are really not flattering. Fortunately, WordPress provides avatar_defaults. The hook allows us to add a custom avatar. Below, Host Select Discount Network will share 2 ways to modify it.
Method 1: Use code to customize WordPress’ default Gravatar avatar
Add the following code before the last ?> in your theme’s functions.php:
//修改默认头像 add_filter('avatar_defaults', 'default_avatar'); function default_avatar($avatar_defaults) { $myavatar = 'https://i.loli.net/2020/07/19/idoODqFrH4XW7J5.jpg';//图文url路径 $avatar_defaults[$myavatar] = "主机精选优惠网";//图片的描述名称 return $avatar_defaults; }
Modification tips:
1. The fourth line of code is the URL address of the avatar. The above is wpdaxue-gravatar.jpg under the images folder of the current theme. Please modify it according to the actual situation;
2. The fifth line is the name of the custom avatar. The above is the default avatar of WordPress University. Please modify it yourself.
After saving, you can see the new avatar in the background - Settings - Discussion, and set it as the default:
Method 2: Use the Add New Default Avatar plug-in
If you don’t want to mess with the code, you can also install the Add New Default Avatar plug-in directly in the background. After enabling it, you can add a custom avatar under the background - Settings - Discussion, which is very Simple.