Filter Hook – user_profile_filter_user_avatar

Vew count: 194

You can extend avatar on user profile page by filter hook as following.

function user_profile_filter_user_avatar($user_avatar){
  
  if(isset($_GET['id'])){
    
    $user_id = sanitize_text_field($_GET['id']);
    //var_dump($user_id);
    }
  else{
    
    $user_id = get_current_user_id(); 
    }
    
  // grab new avatar
  $user_avatar = get_avatar($user_id, 500);
  ?>
      <div class="new-avatar">
      <?php echo $user_avatar; ?>
      </div>
      <?php
  
  }
  
add_filter('user_profile_filter_user_avatar','user_profile_filter_user_avatar');