I am working on a custom WordPress theme and as per design requirements, I have to set the Author Gravatar in the background of a image.
I have tried using get_avatar_url()
with wp_get_attachment_image_src
as below, but could not achieve:
PHP in-line code:
<?php $thumb = wp_get_attachment_image_src(get_avatar_url($post->ID), '80'); ?>
<div class="author" style="background-image: url('<?php echo $thumb[0]; ?>')"></div>
CSS:
.author {
width:120px;
height:120px;
background: no-repeat center;
}
How do I achieve this ?
I have found the answer in here (https://stackoverflow.com/a/29860844/3725816):
Here’s the solution. It’s working fine in my website.