Wordpress: Change profile picture wihout plugin and gravatar

  1. Step 1: go to wp-content/themes/yourtheme/functions.php
  2. write: 

        add_filter'get_avatar''ChangeAdminProfileIfNot'105 );
        function ChangeAdminProfileIfNot( $avatar = '', $id_or_email, $size = 96, $default = '', $alt = '' ) {

            if"user_has_uploaded_a_local_avatar") {
            

                $avatar = "<img src='your image path' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}'";
                
            
            }

            return $avatar;

        }


Note: 
user_has_uploaded_a_local_avatar

This will check user or admin have profile picture

If you want to change profile picture only for admin 
then write:


        add_filter'get_avatar''ChangeAdminProfileIfNot'105 );
        function ChangeAdminProfileIfNot( $avatar = '', $id_or_email, $size = 96, $default = '', $alt = '' ) {

            if"user_has_uploaded_a_local_avatar"  && strpos($avatar'524839ea4d48eb11da1325dc1bfccc14') !== FALSE) {
            

                $avatar = "<img src='new image path' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}'";
                
            
            }

            return $avatar;

        }


524839ea4d48eb11da1325dc1bfccc14 
this is my admin image id. find your image id. You can check your image id using inspect element.

Comments