Customize Topbar menu

Hello everyone, 

I'll desperately try to personallze the topbar menu in Elgg 2.3.3. I've tryed to use the elgg_unregister_menu_item to remove element from the topbar like the documentation says to do, but that doesn't seem to work. Is anyone have a functionnal idea ?

Thank by advance

  • Which item's name? Bcz, some items cann't customize with this hook.

  • In the better case I want to remove all the elements, so I can reorder and add some css classes on them, without breaking the menu mecanism. 

    for example, the dashboard or site_notifications, can be remove, but that doesn't work with friends, messages or profile.





  • Messages:

    elgg_unregister_plugin_hook_handler('register', 'menu:topbar', 'messages_register_topbar');


    elgg_unregister_menu_item('topbar', 'friends'); //Works fine


    elgg_unregister_event_handler('pagesetup', 'system', 'profile_pagesetup');

    Also, check your activated theme. Perhaps, there are the rewrited hooks/views

  • Ok thanks, that works for profile and messages but not for Friends. 

    That not really simple to make a theme in Elgg. It's a pity that's not standardized for all the menu items.


  • but not for Friends

    Then override _elgg_friends_page_setup:

    elgg_unregister_event_handler('pagesetup', 'system', '_elgg_friends_page_setup');
    elgg_register_event_handler('pagesetup', 'system', 'my_friends_page_setup');
    function my_friends_page_setup() {
        $owner = elgg_get_page_owner_entity();
        $viewer = elgg_get_logged_in_user_entity();
        if ($owner) {
            $params = array(
                'name' => 'friends',
                'text' => elgg_echo('friends'),
                'href' => 'friends/' . $owner->username,
                'contexts' => array('friends')
            elgg_register_menu_item('page', $params);
            $params = array(
                'name' => 'friends:of',
                'text' => elgg_echo('friends:of'),
                'href' => 'friendsof/' . $owner->username,
                'contexts' => array('friends')
            elgg_register_menu_item('page', $params);
  • Yeah thanks that works fine.

    I've just found this method too:

     $item = elgg_get_menu_item('topbar', 'messages');
            if ($item) {

    So I can manipulate the menu item without breaking the standard mecanism.

    But seem to doesn't work with all, 

  • There is a menu hook intended just for this:

    // register with higher priority so it's called after all other hooks
    elgg_register_plugin_hook_handler('register', 'menu:topbar', 'modify_topbar_menu', 1000);
    function modify_topbar_menu($hook, $type, $return, $params) {
       $remove = ['friends'];
       foreach ($return as $key => $item) {
          /* @var $item \ElggMenuItem */
          if (in_array($item->getName(), $remove) {
          switch ($item->getName()) {
              case 'profile' :
          $return[$key] = $item;
       return $return;