Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

comment template - gravatar image as background image WordPress


Trying to make a custom comment section.

What's the correct PHP to use to create this?

<div class="avatar" style="background: url(></div>
<div class="comment">This is a comment.</div>

Answers (1)


Andrzej answers:

put this to your functions.php:

function my_get_avatar_filter($avatar_html) {
$exp1 = explode("src='", $avatar_html);
$exp2 = explode("'", $exp1[1]);
return $exp2[0];

and this in comments template:
<div class="avatar" style="background: url(<?php echo my_get_avatar_filter(get_avatar($comment)) ?>);"></div>
<div class="comment">This is a comment.</div>