Как установить Gravatar в качестве фонового изображения в WordPress?

Я работаю над пользовательской темой WordPress, и в соответствии с требованиями к дизайну, я должен установить Автор Gravatar на фоне изображения.

Я пытался использовать get_avatar_url() с wp_get_attachment_image_src как показано ниже, но не смог достичь:

Встроенный код PHP:

<?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;
}

Как мне этого добиться?

1

Решение

Я нашел ответ здесь (https://stackoverflow.com/a/29860844/3725816):

function my_gravatar_url() { // Get user email
$user_email = get_the_author_meta('user_email');
// Convert email into md5 hash and set image size to 80 px
$user_gravatar_url = 'http://www.gravatar.com/avatar/' . md5($user_email) . '?s=120';
echo $user_gravatar_url;
}<div class="author" style="background: url('<?php echo my_gravatar_url(); ?>') center center no-repeat; top: 50%; left: 50%;">
</div>
1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector