1

I need to show the user register link as a menu item in the account menu. I am able to add the link in the menu via links.menu.yml.

The menu links shows up for anonymous users as well as authenticated users but not for admin user role.

How can I hide the menu item for logged in users irrespective of user role?

  • have you created a custom menu link? – Shreya Shetty May 6 '16 at 8:55
  • Look at RouteSubscriber, in 8 it is the new way to hook_menu_alter - api.drupal.org/api/drupal/… – Dylan May 8 '16 at 19:17
  • Using RouteSubscriber we can alter the visibility of a menu item but it doesn't effect the admin users. – Malabya Tewari May 9 '16 at 7:46
1

Tried all the options to hide the menu item from authenticated users irrespective of the role, but admin always sees it. Did that using CSS and Menu Link Attributed module. Using the module I added a class to the menu link and then using the body class user-logged-in hid the menu item for logged in user.

I am still open to any other alternative and a better solution.

1

In case someone bumps here again, I found two ways it can be achieved within a theme without using any using module.

1) Using custom CSS:

.user-logged-in .menu.menu--account a[href="/user/register"] { display: none; }

2) Using custom JS:

$('.user-logged-in').find('.menu.menu--account a[href="/user/register"]').hide();

This is applicable only if you are customizing your theme in any way.

0

You can do this: group references in several menus: for registered - one for guests - another, etc. Then configure the units display, in which the menus are displayed on the page. The unit registered only show the registered menu.

0

Try the Menu Per Role Module. The new maintainer is trying to take over the drupal.org project but he has his code up on Github.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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