我想知道是否有办法在 wordpress 中获取当前登录用户头像的 URI/URL?我发现这是一种生成简码以使用 get_avatar 插入当前用户头像的方法(在 php 下方放置在主题 functions.php 中):
<?php
function logged_in_user_avatar_shortcode() {
if ( is_user_logged_in() ) {
global $current_user;
get_currentuserinfo();
return get_avatar( $current_user->ID );
}
}
add_shortcode('logged-in-user-avatar', 'logged_in_user_avatar_shortcode');
?>
但是,这会返回整个图像,包括属性(img src、class、width、height、alt)。我想只返回 URL,因为我已经在模板中为我的图像设置了所有属性。
试图做这样的事情:
<img src="[shortcode-for-avatar-url]" class="myclass" etc >
有谁知道这样做的方法?
提前谢谢了