User name in topbar

This question is about the profile icon in top bar left. Is it possible to add the user name after it? Using Elgg 1.8.13.

  • Use this hook:

     

            $user = elgg_get_logged_in_user_entity();

            elgg_unregister_menu_item('topbar', 'profile');
            elgg_register_menu_item('topbar', array(
                'href' => "/profile/$user->username",
                'name' => 'account',
                'text' => $user->name,
                'title' => $user->name,
            ));

  • Thanks RvR. Will research about "hooks" and try and figure out what script to add it to.

  • Try my 'dumbest' plugin

    In start.php add above code instead of

    Line 18: elgg_unregister_menu_item('topbar', 'profile');

  • if you want to move it left or right in the top bar then add this to the array

    'priority' => 10, // this will put the username on the left side of the image

  • Many thanks RvR - works like a charm! Only thing is the user avatar is gone but that really doesn't matter.

    Cim, priority not needed as it's exactly where I wanted it. Good to know for future though - thanks.

  • @jon666 I've thinked that you want replace avatar with username :)

    If you want to display avatar and username both then you need this code:

     

            $user = elgg_get_logged_in_user_entity();

            elgg_unregister_menu_item('topbar', 'profile');
            elgg_register_menu_item('topbar', array(
                'href' => "/profile/$user->username",
                'name' => 'account',
                'text' => "<img src=\"{$user->getIconURL('topbar')}\" class=\"elgg-icon elgg-inline-block\" alt=\"$user->name\"/>" .$user->name,
                'title' => $user->name,
            ));

  • just comment out or remove this line of code

            elgg_unregister_menu_item('topbar', 'profile');

  • @RvR

    Trying to do this to display both Avatar and Name for logged in User.. am using Elgg 1.8 with Social Login

    Made a plugin and could activate it via Admin login .after activation the Admin User Icon and Name come up fine. But after Admin logs out, there is simply a blank page.. once the plugin is deleted, normal behavior resumes.

    How to correct ? pl advise...am a just cut and paste coder so all details much appreciated, thanks!