I've made a small function which checks if a user has an avatar. If so, the avatar is set as a background URL for a div. However, when checking the console on the frontend, slashes are missing from the URL, thus not displaying the background image.
function small_avatar($user_ID){
$avatar = get_user_meta($user_ID, 'avatar_user', true);
if(!empty($avatar)){
return "<div class='setAvatar clan_avatar' style='background: url('".$avatar."');'></div>";
}
}
The use of " and ' is probably breaking something but.. I can't figure it out. Tried to set the style='background' as a variable, and tried to return that as well. No luck.
asked Apr 20, 2017 at 13:33
Kevinster
671 gold badge2 silver badges9 bronze badges
1 Answer 1
Sigh..
All I needed to do was remove the " from the url()
So this works:
function small_avatar($user_ID){
$avatar = get_user_meta($user_ID, 'avatar_user', true);
if(!empty($avatar)){
return "<div class='setAvatar clan_avatar' style='background: url(".$avatar.");'></div>";
}
}
answered Apr 20, 2017 at 13:40
Kevinster
671 gold badge2 silver badges9 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-php
$avatarhas the string with shlashes?