
Changing Default User Avatar in WordPress
- September 28, 2016
- Leave a comment
WordPress has a default avatar for users who register themselves on a particular WP site. Instead of using a default avatar, users can upload their own profile avatar. In this article, you will learn how to change the default user avatar.
Seven default avatars are available in WordPress; a user/admin can select any of them. From WordPress Dashboard admin menu, just navigate to Settings->Discussion.
In the screenshot above, default avatars are listed as follows:
- Mystery Person
- Blank
- Gravatar Logo
- Identicon (Generated)
- Wavatar (Generated)
- MonsterID (Generated)
- Retro (Generated)
“Mystery Person” is selected by default. Additionally, you can see in the screenshot “PressTigers Avatar“, which is a custom avatar added by using the following code:
1 2 3 4 5 6 |
function pt_avatar_defaults($avatar_defaults) { $myavatar = get_stylesheet_directory_uri() . '/assets/images/sa_default.jpg'; $avatar_defaults[$myavatar] = "PressTigers Avatar"; return $avatar_defaults; } add_filter('avatar_defaults', 'pt_avatar_defaults'); |
With this code, “avatar_defaults” filter will add a new avatar option in the list. The filter function has one array “$avatar_defaults“. This array contains the list of default avatars and you can add or remove any of them. To add a new default avatar in the list, following two inputs are required:
- Avatar Image URL
- Name of the Avatar
For the above mentioned case, we have the following URL and name:
1 2 |
$myavatar = get_stylesheet_directory_uri() . '/images/pt_default.jpg'; $avatar_defaults[$myavatar] = "PressTigers Avatar"; |
Now, create a variable “$myavatar” and assign the image URL to it. After that, add “$myavatar” to the “$avatar_defaults” array. At the end, this array will be returned and the new avatar will be added in the default avatar list.
User Comments