在帖子/页面上显示登录用户的Wordpress头像


Display Wordpress avatar for logged-in user on post/page

我正试图找到一种方法,在我的一个页面上显示登录用户的个人头像/gravatar(基于他们的电子邮件地址)。

到目前为止,我只能找到显示页面作者头像的方法,或者为所有用户显示相同的头像。

我想我需要将get_avatar添加到我的functions.php中,使用如下内容:

< a href = "<?php echo get_author_posts_url($post->post_author); ?>"
title = "<?php the_author_meta( 'display_name', $post->post_author ); ?>" >
  <? php
if (get_the_author_meta('user_custom_avatar', $post - > post_author) != '') { ?>
  < img src = "<?php the_author_meta( 'user_custom_avatar', $post->post_author ); ?>"
  alt = "" / >
    <? php echo $curauth - > display_name; ?>
  <? php
} else {
  $current_user = wp_get_current_user();
  echo get_avatar($current_user - > user_email, $post - > post_author), '80');
} ?>
< /a>

但我也需要知道如何在我的页面/帖子的内容中显示它。使用Wordpress编辑页面时,有什么可以使用的东西吗?

如有任何帮助,我们将不胜感激!

在任何页面或帖子中,都可以这样调用

 $custom_avatar = get_user_meta($user_id, 'user_custom_avatar', true);