I was wondering if there is a way to get the URI/URL of the current logged-in user's avatar in wordpress? I found this as a way to generate a shortcode to insert the current user avatar using get_avatar (below php to be placed in theme 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');
?>
However, this returns the whole image including attributes (img src, class, width, height, alt). I want to return just the URL alone because i have already set all the attributes for my image in the template.
Trying to make something like this:
<img src="[shortcode-for-avatar-url]" class="myclass" etc >
Does anyone know a way to do this?
Many thanks in advance
I know this is a old question, but for anyone looking, there's a more concise way to get the avatar url with
get_avatar_url()
. (More info here.)