Darko Darko - 1 month ago 13
PHP Question

Image URL appears in a wrong place in WordPress shortcode output

I'm trying to make a shortcode for displaying logged in user avatar from buddypress

// user avtar
function user_avatar() {
$user_avatar_url = bp_loggedin_user_avatar('type=full&html=false');
$user_image = '<img src="' . $user_avatar_url . '"/>';
return $user_image;
}
add_shortcode('avatar', 'user_avatar');


but when I try to insert shortcode [avatar], the HTML output looks like this:

http://localhost/.../images/bp_default_avatar.jpg <img src=""></img>


Somehow image url/src appears before 'img' tag?

Answer

Apparently it was the buddypress issue, I changed a few things and now it's working

// user avtar
function user_avatar() {
$userid = bp_loggedin_user_id();
$user_avatar_url = $avatarurl = bp_core_fetch_avatar( array( 'item_id' => $userid, 'html' => false ) ); 
$user_image = '<img src="' . $user_avatar_url  . '"/>';
return $user_image;

}
add_shortcode('avatar', 'user_avatar');
Comments