X
    Categories: Wordpress

How to change admin avatar in wordpress?

How to change admin avatar in wordpress?

By default wordpress provide gravator for admin avatar . The gravator will call from out side of our server so there is an change of affecting website speed. So i have decide to change from gravator to user defined avatar . I have searched many time for plugin or some other solution but It could’t helped me. So I have coded manually. It works fine for me and now I am using my code in my blog. Its working fine for me. This may help someone to change the image and save the time.

Let’s see how to remove gravatar from wordpress and setting new admin avatar .

1. Go to “wp-includes/pluggable.php” and find below code (under function get_avatar()):-

$avatar = "<img alt='{$safe_alt}' src='{$out}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";

And replace it with below code :-

$get_admin_user = get_user_by_email($email);
if(is_super_admin($get_admin_user->ID)) {
  if(($useravatar = get_user_meta($get_admin_user->ID, 'admin_user_thumbnail', true)) !== false AND strlen(trim($useravatar)) > 0){
    $avatar = "<img alt='{$safe_alt}' src='".get_template_directory_uri().$useravatar."' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
  }
}  
else {
  $avatar = "<img alt='{$safe_alt}' src='{$out}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
}

2. Add or insert new row in user_meta table in your database.

user_id = 1 //admin userid if any other
meta_key = admin_user_thumbnail
meta_value = /images/myadminimage.png  // give a path "your_active_theme/images"

3. upload your admin image(myadminimage.png) in “wp-content/themes/your_active_theme/images/”.

Now refresh your site you will get new image on admin bar and every where you have admin profile pic on site. so this is a manually doing simple method to change profile picture in wordpress.

Thanks!. If you like this article don’t forget to share and comment.

Marimuthu:

View Comments