I’m trying to add Pinterest’s nopin=”nopin” HTML attribute to the comment avatar image tags on my blog. Here’s the function I’m using to call the avatar on each comment:

get_avatar($comment, 50, vol_random_image())

vol_random_image() just selects an image from an array if the commenter doesn’t have a Gravatar.

I know get_avatar has an $alt attribute, but that only sets an alt tag, right? How would I go about adding this custom HTML tag?

Full code of the function:

echo "<li ", comment_class(), " id=\"li-comment-", comment_ID(), "\">\n
\t<article id=\"comment-", comment_ID(), "\" class=\"comment\">\n
\t\t<footer>\n
{$tab3}<div class=\"comment-author vcard\">\n
{$tab3}\t<div class=\"comment-avatar\">\n",
get_avatar($comment, 50, vol_random_image()),
"{$tab3}\t</div>\n
{$tab3}</div>\n" .
(($comment->comment_approved == '0') ? 
    sprintf("{$tab3}<em>") . __('Your comment is awaiting moderation.', 'volatyl') . sprintf("</em><br />\n") : 
'') .
"{$tab3}<div class=\"comment-meta commentmetadata\">\n{$tab3}\t" .
sprintf('<cite class="fn">%s</cite>', get_comment_author_link()) .
"\n{$tab3}\t<div class=\"comment-date\">\n
{$tab3}\t\t<a href=\"", esc_url(get_comment_link($comment->comment_ID)), "\"><time pubdate datetime=\"", comment_time('c'), "\">";

3 Answers
3

You can use the get_avatar filter to modify the output of the image tag and add your HTML attribute

return apply_filters( 'get_avatar', $avatar, $id_or_email, $size, $default, $alt );

$avatar : Image tag for the user's avatar.

Leave a Reply

Your email address will not be published. Required fields are marked *