MyBB Community Forums

Full Version: Need hlep displaying member avatar in header.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to display the members avatar in the header as shown in the photo1 below.

I have it working properly with the following code inserted into the top of  the [header_welcomeblock_member] template as long as the member has uploaded his own avatar instead of using the default avatar.

<a href="usercp.php?action=avatar" title="click"><img src="{$mybb->user['avatar']}" id="headeravatar"></a><span class="welcome">{$lang->welcome_back} &nbsp;&nbsp;<a href="{$mybb->settings['bburl']}/member.php?action=logout&amp;logoutkey={$mybb->user['logoutkey']}"><span id="logbutton">{$lang->welcome_logout}</span></a>
</div><span class="smalltext">Click to change avatar</span>

If the member is still using the default avatar it isn't displayed as you can see in photo2. What can I do to get the default avatar to display in the header when an the member hasn't uploaded a custom avatar?  - Thanks!

Photo1:
[attachment=37741]

Photo2:
[attachment=37742]
You can do it without a plugin, just upload a default avatar in your themes images folder.

<a class="header_avatar" href="{$mybb->settings['bburl']}/usercp.php?action=avatar"> <img src="{$mybb->user['avatar']}" height="25px" width="25px" /></a>

<script>
$(document).ready(function() {
//create a default avatar for those without one.
if($('.header_avatar img', this).attr('src') == ''){
$('.header_avatar img').attr('src', "images/default_avatar.png");
}
});
</script>
Thanks you so much! That code worked perfectly. Just what I was looking for. Big Grin
(2016-11-02, 05:01 PM)iAndrew Wrote: [ -> ]You can do it without a plugin, just upload a default avatar in your themes images folder.

<a class="header_avatar" href="{$mybb->settings['bburl']}/usercp.php?action=avatar"> <img src="{$mybb->user['avatar']}" height="25px" width="25px" /></a>

<script>
$(document).ready(function() {
//create a default avatar for those without one.
if($('.header_avatar img', this).attr('src') == ''){
$('.header_avatar img').attr('src', "images/default_avatar.png");
}
});
</script>

The code above worked great in the header template. I would like to do the same in the changeuserbox template next to the username when a member is making a reply or new post but if a member has a default avatar, the default avatar doesn't show up. How can I modify the code to make it work in the changeuserbox template?

BTW, I don't use the change user feature in that template. I only show the username
Thanks!

[attachment=37768]