I'm new to drupal and using the latest version (7.x). I want hide the Main Menu in all pages until user log-in to the site. I set the Main Menu block role set to "Authenticated Users" only. But I can see the Main Menu on all pages as anonymous user.

How could I hide the Main Menu for anonymous user and show them once logged In ?

  • Check your page.tpl file, may be its rendering Main menu. If it is from page.tpl then just add the condition before rendering the Main menu. – inizio Jan 15 '14 at 6:24

If you are assigning main menu (as block) to region, you can control it's visibility by "Visibility settings". If you are rendering it in .tpl.php file then you can do it like this: Example (bartik's page.tpl.php):

<?php if ($main_menu && user_is_logged_in()): ?>
  <div id="main-menu" class="navigation">
    <?php print theme('links__system_main_menu', array(
      'links' => $main_menu,
      'attributes' => array(
        'id' => 'main-menu-links',
        'class' => array('links', 'clearfix'),
      'heading' => array(
        'text' => t('Main menu'),
        'level' => 'h2',
        'class' => array('element-invisible'),
    )); ?>
  </div> <!-- /#main-menu -->
<?php endif; ?>
| improve this answer | |

enter image description here

When you move to the menu block configure settings there is tab for role. You can restrict it to authenticated users only. This would work.

| improve this answer | |

Use this module https://www.drupal.org/project/menu_item_visibility The module uses the exact same UI used for block visibility settings for familiarity.

| improve this answer | |

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.