Adding a button to profile menu

I am trying to add a button to the profile menu by the 'EDIT PROFILE' button.

I have added the following code to the start file of my plugin.....

elgg_register_plugin_hook_handler('register', 'SOMETHING_HERE', 'my_owner_menu_button');

But cannot find out what to add to the 'SOMETHING_HERE' bit of code.

Can anyone help me with this please ?? 


  • menu:user_hover


    If I remember correctly you'll need to set the section to 'action' for it to show up in the owner block

  • Hi Matt.

    I think I might be trying to run before I can walk with this but I will try.

    Do you mean like this...

    elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'cmy_upgrade_owner_block_menu');

    and then set the action in a function.

    I have been looking around the reference and docs and found this

    if (elgg_is_logged_in() && $actions) {
    echo '<li>';
    echo elgg_view('navigation/menu/elements/section', array(
    'class' => "elgg-menu elgg-menu-hover-actions",
    'items' => $actions,
    echo '</li>';

    Looks like what I might need as I only want the menu button to show when the user is logged in.

    Thanks for your help!

  • @JohnnyD

    Correct me, pls: Owner block or User hover?


    For adding link on the owner block use this example:

    elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'my_owner_block_menu');


    function my_owner_block_menu($hook, $type, $return, $params) {
        if (elgg_instanceof($params['entity'], 'user')) {
            $url = "YOUR_LINK_HERE";
            $item = new ElggMenuItem('my', elgg_echo('my'), $url);
            $return[] = $item;

        return $return;


    For user hover use this hook:

    elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'my_user_hover_menu');


    function my_user_hover_menu($hook, $type, $return, $params) {
        $url = "YOUR_LINK_HERE";
        $item = new ElggMenuItem('my', elgg_echo('my'), $url);
        $return[] = $item;
        return $return;

  • Hi RvR,

    Thank you for your help.

    I am trying to add a button on the profile page with the 'edit avatar' and 'edit profile' like in this image.


    I would like it to only show when the profile owner is logged in.

    Sorry I copied the wrong bit of code in my last reply. It should have been...

    Do you mean like this...

    elgg_register_plugin_hook_handler('action', 'menu:user_hover', 'my_owner_menu_button');

    and then set the action in a function.

    Thanks to you both.


  • Use


    if (elgg_is_logged_in()) {

    elgg_register_menu_item('page', array(
                'name' => 'YOUR_BUTTON_NAME',
                'href' => "YOUR_LINK_TO_ACTION",
                'text' => elgg_echo('YOUR_BUTTON_NAME'),

                'link_class' => 'elgg-button elgg-button-action',
                'contexts' => array('profile'),


  • @RvR: this will show the button to all logged in users and not exclusively to the page owner.

    @JohnnyD: try this...

    Add to the init function of your plugin:

    // Extend avatar hover menu
    elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'callback_function_for_adding_button');

    and the callback function for this plugin hook is:

    function callback_function_for_adding_button($hook, $type, $return, $params) {
        $user = $params['entity'];

        if (elgg_get_logged_in_user_guid() == $user->guid) {
            $url = < What should the button link to? Provide the url>
            $item = new ElggMenuItem('button_name', elgg_echo("Button Text"), $url);
            $return[] = $item;

        return $return;

    I think this should add the button on profile pages (visible only to the profile page owner). It will also add the link to the hover menu of user avatars (also only visible on your own). The entry in the hover menu is created automatically. I don't know how to get only the button on profile pages without the entry in the hover menu

  • @RvR Thanks for the code. It added the button to the sidebar instead of with the edit buttons. But it worked ok.

    Also like iionly said it shows to all logged in users.


    Thanks for the help! I will try it tomorrow as my head is spinning now and I will only make mistakes. With the hover menu will work fine also. I will let you know how I get on tomorrow.

    Thanks everyone.

  • No, those buttons are generated in a weird way - it comes from the user_hover menu, I've had to work with them before

    elgg_register_plugin_hook('register', 'menu:user_hover', 'my_function');

    function my_function($hook, $type, $return, $params) {

      $item = new ElggMenuItem('button_name', elgg_echo('button_text'), $url);


      $return[] = $item;

      return $return;


  • @iionly and Matt

    That worked great and it also added the link to the hover menu of user avatars which works well. 

    I worked most of yesterday on this with no luck but with your help got it working in 5 minutes this morning.

    Thanks again for your help.



Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking