---
description: >-
  https://wordpress.stackexchange.com/questions/195196/how-to-change-gravatar-size-when-using-comments-template
---

# How to change Gravatar size when using comments\_template (ok)



Asked 5 years, 9 months agoActive [3 years ago](https://wordpress.stackexchange.com/questions/195196/how-to-change-gravatar-size-when-using-comments-template?lastactivity)Viewed 1k times11

I am trying to change default Gravatar size. Since I am using WP-generated comments template (using comments\_template() function), I turned to filters and this is my custom code:

```
function change_avatar_size ( $id_or_email, $size = 100, $default = '', $alt = '', $args = null ) {

    $args['size']    = (int) $size;  

    $url2x = get_avatar_url( $id_or_email, array_merge( $args, array( 'size' => $args['size'] * 2 ) ) );

    $args = get_avatar_data( $id_or_email, $args );

    $url = $args['url']; 

    $class = array( 'avatar', 'avatar-' . (int) $args['size'], 'photo' );  

    $avatar = sprintf(
        "<img alt='%s' src='%s' srcset='%s' class='%s' height='%d' width='%d' %s/>",
        esc_attr( $args['alt'] ),
        esc_url( $url ),
        esc_attr( "$url2x 2x" ),
        esc_attr( join( ' ', $class ) ),
        (int) $args['height'],
        (int) $args['width'],
        $args['extra_attr']
    );

    return $avatar;

}
add_filter( 'get_avatar', 'change_avatar_size' );
```

The size does change, but I am not getting the correct Gravatar URL. I am getting default Gravatar image actually, as if the generated link is not correct. Any ideas?[gravatar](https://wordpress.stackexchange.com/questions/tagged/gravatar)[Share](https://wordpress.stackexchange.com/q/195196)[Improve this question](https://wordpress.stackexchange.com/posts/195196/edit)Follow[edited Nov 21 '15 at 13:29](https://wordpress.stackexchange.com/posts/195196/revisions)[![](https://i.stack.imgur.com/GFbnl.jpg?s=32\&g=1)](https://wordpress.stackexchange.com/users/38123/bryan-willis)[Bryan Willis](https://wordpress.stackexchange.com/users/38123/bryan-willis)3,89922 gold badges2727 silver badges4141 bronze badgesasked Jul 21 '15 at 20:54[![](https://www.gravatar.com/avatar/ed4d4557f19edb6952c852543ab7e1f9?s=32\&d=identicon\&r=PG)](https://wordpress.stackexchange.com/users/19499/bruno-kos)[Bruno Kos](https://wordpress.stackexchange.com/users/19499/bruno-kos)27811 silver badge99 bronze badges[Add a comment](https://wordpress.stackexchange.com/questions/195196/how-to-change-gravatar-size-when-using-comments-template)

### 2 Answers

[Active](https://wordpress.stackexchange.com/questions/195196/how-to-change-gravatar-size-when-using-comments-template?answertab=active#tab-top)[Oldest](https://wordpress.stackexchange.com/questions/195196/how-to-change-gravatar-size-when-using-comments-template?answertab=oldest#tab-top)[Votes](https://wordpress.stackexchange.com/questions/195196/how-to-change-gravatar-size-when-using-comments-template?answertab=votes#tab-top)3

Here's how to do it using the method Bruno went with (for others wondering this):

```
wp_list_comments( array(
    'avatar_size' => 32
) );
```

You can also do it [this way](https://wordpress.stackexchange.com/a/210633/43806) depending on your use case:

```
global $comment;
echo get_avatar($comment, 64)
```
