I want to remove the "My Account" and "Log out" menu links, as I've incorporated those into other parts of the page.

Now, I'm a Drupal novice so if I'm making rookie mistakes here go easy!

What I've tried is something like this in my module.install file

function mymodule_enable()
    menu_link_delete(null, 'user');
    menu_link_delete(null, 'user/logout');

Now - that doesn't work as those two menu links are 'system' links. I tried to brute force this by creating a variant of menu_link_delete which forces deletion, by passing "true" to the $force parameter of _menu_delete_item...

function force_menu_link_delete($mlid, $path = NULL) {
    if (isset($mlid)) {
        _menu_delete_item(db_query("SELECT * FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $mlid))->fetchAssoc(), true);
    } else {
        $result = db_query("SELECT * FROM {menu_links} WHERE link_path = :link_path", array(':link_path' => $path));
        foreach ($result as $link) {
            _menu_delete_item($link, true);

When my module is enabled, that does successfully delete the relevant rows of the menu_link table, but by the time the Drupal has finished working its magic they have reappeared in the table!

The reason of course is that the user_menu() hook goes and reestablishes them. I wondered if removing them with a menu_alter hook would work...

function mymodule_menu_alter(&$items) {

Sure enough, they disappear, but so does the actual capability to logout!

So - I'm going about this the wrong way. I'm guessing I shouldn't try to delete the menu links themselves, but somehow prevent my theme from displaying them.

Pointers are very welcome....

1 Answer 1


Not sure if this is the correct approach, but it worked - I used a menu_alter hook to move the menu items to a different menu.

function mymodule_menu_alter(&$items) {
    $items['user']['menu_name'] = 'unused-menu';
    $items['user/logout']['menu_name'] = 'unused-menu';
  • That'll do it :)
    – Clive
    Apr 26, 2013 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.