最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

theme development - Adding custom class to get_avatar() image doesn't work

matteradmin7PV0评论

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).

Post a comment

comment list (0)

  1. No comments so far