【发布时间】:2014-02-14 03:18:12
【问题描述】:
我想知道是否有办法在 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 >
有人知道怎么做吗?
在此先感谢
【问题讨论】:
-
很丑,但是有答案here
-
据我所知,WP 没有仅返回 URL 的选项。或者至少,法典似乎没有提到它。所以上面的链接可能是你最好的选择。
-
哦,该死的。我尝试在链接上使用第一个解决方案,它几乎可以工作,但总是为每个用户显示相同的模板头像。
标签: php wordpress shortcode avatar codex