admin管理员组

文章数量:1024582

Instead of outputting

<img alt="" src="#" srcset="#" class="avatar avatar-60 photo" height="60" width="60">

I want to add custom class which looks like

<img alt="" src="#" srcset="#" class="avatar avatar-60 photo myclass" height="60" width="60">

To achieve this, I tried to use

get_avatar( $comment, $args['avatar_size'], '', '', array('class' => 'myclass') );

However it doesn't change anything. Any help guys?

Instead of outputting

<img alt="" src="#" srcset="#" class="avatar avatar-60 photo" height="60" width="60">

I want to add custom class which looks like

<img alt="" src="#" srcset="#" class="avatar avatar-60 photo myclass" height="60" width="60">

To achieve this, I tried to use

get_avatar( $comment, $args['avatar_size'], '', '', array('class' => 'myclass') );

However it doesn't change anything. Any help guys?

Share Improve this question asked Nov 6, 2018 at 21:47 p onelandp oneland 171 silver badge8 bronze badges 1
  • 1 Perhaps the get_avatar filter is being run somewhere within the active theme or a plugin. This would modify the output of your call to get_avatar(). Try searching within the files for get_avatar. – Dave Romsey Commented Nov 6, 2018 at 22:51
Add a comment  | 

1 Answer 1

Reset to default 0

The following worked for me:

<?php echo get_avatar( $comment, 60, '', '', $args = array( 'scheme' => 'https', 'class' => 'myclass' ) ); ?>

Your use of $args['avatar_size'] should be an int and you may have confused the use of this parameter (unless you have a variable $args, and it is an array).

Instead of outputting

<img alt="" src="#" srcset="#" class="avatar avatar-60 photo" height="60" width="60">

I want to add custom class which looks like

<img alt="" src="#" srcset="#" class="avatar avatar-60 photo myclass" height="60" width="60">

To achieve this, I tried to use

get_avatar( $comment, $args['avatar_size'], '', '', array('class' => 'myclass') );

However it doesn't change anything. Any help guys?

Instead of outputting

<img alt="" src="#" srcset="#" class="avatar avatar-60 photo" height="60" width="60">

I want to add custom class which looks like

<img alt="" src="#" srcset="#" class="avatar avatar-60 photo myclass" height="60" width="60">

To achieve this, I tried to use

get_avatar( $comment, $args['avatar_size'], '', '', array('class' => 'myclass') );

However it doesn't change anything. Any help guys?

Share Improve this question asked Nov 6, 2018 at 21:47 p onelandp oneland 171 silver badge8 bronze badges 1
  • 1 Perhaps the get_avatar filter is being run somewhere within the active theme or a plugin. This would modify the output of your call to get_avatar(). Try searching within the files for get_avatar. – Dave Romsey Commented Nov 6, 2018 at 22:51
Add a comment  | 

1 Answer 1

Reset to default 0

The following worked for me:

<?php echo get_avatar( $comment, 60, '', '', $args = array( 'scheme' => 'https', 'class' => 'myclass' ) ); ?>

Your use of $args['avatar_size'] should be an int and you may have confused the use of this parameter (unless you have a variable $args, and it is an array).

本文标签: theme developmentAdding custom class to getavatar() image doesn39t work