0

I am using a custom walker class to customize my comments section. It uses the following code to get the comment author image from gravatar

<?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>

The HTML output is as following

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

I want to add a custom class to the <img> tag so the output will be like this

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

How do I do that ?

1

The get_avatar() function has many arguments, the last one is the interesting one, because you can pass additional classes, also described in the codex. So instead of

get_avatar( $comment, $args['avatar_size'] );

you could use

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy