How can i remove menu item from entity menu

I am simply unable to remove the menu items from the entity menu. I want to remove the access, like and delete menus from the blog-listings(example.com/blog/all) to show up. I only need blog title, sub-text, excerpt and the entity-menu(without access, like and delete) on the blog listing page. The following line of code does't worked for me 

elgg_unregister_menu_item('menu:entity', 'access');

I know this is very simple but i am unable to find any solution no this. please guide me to the right way. Thanks .

  • On all site

    For Likes

    elgg_unregister_plugin_hook_handler('register', 'menu:entity', 'likes_entity_menu_setup');

    For Delete and Access

    elgg_unregister_plugin_hook_handler('register', 'menu:entity', 'elgg_entity_menu_setup');

    elgg_register_plugin_hook_handler('register', 'menu:entity', 'my_entity_menu_setup');

     

    function my_entity_menu_setup($hook, $type, $return, $params) {
        if (elgg_in_context('widgets')) {
            return $return;
        }
        
        $entity = $params['entity'];
      
        $handler = elgg_extract('handler', $params, false);

       if ($entity->canEdit() && $handler) {
            // edit link
            $options = array(
                'name' => 'edit',
                'text' => elgg_echo('edit'),
                'href' => "$handler/edit/{$entity->getGUID()}",
                'priority' => 100,
            );
            $return[] = ElggMenuItem::factory($options);
        }

        return $return;
    }

     

    On Blogs only

    Another way:

    elgg_register_plugin_hook_handler('register', 'menu:entity', 'blog_setup_entity_menu_items');

    function blog_setup_entity_menu_items($hook, $type, $value, $params) {
        $handler = elgg_extract('handler', $params, false);
        if ($handler != 'blog') {
            return $value;
        }

        foreach ($value as $index => $item) {
            $name = $item->getName();
            if ($name == 'access' || $name == 'delete' || $name == 'likes') {
                unset($value[$index]);
            }
        }

        $entity = $params['entity'];

       if ($entity->canEdit() && $handler) {
            // edit link
            $options = array(
                'name' => 'edit',
                'text' => elgg_echo('edit'),
                'href' => "$handler/edit/{$entity->getGUID()}",
                'priority' => 100,
            );
            $value[] = ElggMenuItem::factory($options);
        }

        return $value;
    }

  • Thanks @rivervanrain for taking time, much appreciated. I have just made this to work. The 2nd approach worked for me. Thanks a lot .