4

I have a menu that displays on every page, and the top link for that menu is the "Home" link. The clients do not want this menu item to appear when a user is viewing the home page, but wish it to be there at all other times. How can this be accomplished? There's no way I see to set an excluded page for menu item links.

5

Here is one method, and I must confess it may not be the absolute best. This method works for a menu that is not inside a block.

In your page.tpl.php use the following snippet:

if (drupal_is_front_page()) {
  foreach ($primary_links as $key => $value) {
    if (in_array('Home', $value)) {
      unset($primary_links[$key]);
    }
  }
}

The snippet will hide the element that contains the value 'Home' in the 'title' attribute.

Place that snippet before this chunk of code (so that $primary_links is modified before it is printed out):

<?php if (isset($primary_links)) : ?>
   <?php print theme('links', $primary_links, array('class' => 'links primary-links')) ?>
<?php endif; ?>
  • 3
    I think its better if you put this snippet in template.php on the hook_preprocess_page. Just to follow the Drupal Standards. – yvan Aug 25 '11 at 5:38
  • 1
    I actually started in template_preprocess_page, but always ended up with a WSOD for some reason. – Jukebox Aug 25 '11 at 5:48
2

You could also do it with CSS. Get the class for the front page - which might be something like .page-front - and the class for the menu item - which might be something like .main-menu ul li.first - and hide it.

So your CSS would look sort of like this -

.page-front .main-menu ul li.first {visibility:hidden;width:0px}

That'll blank out that one menu item and move the rest over seamlessly.

0

I ended up putting the home link in a separate menu/block, then set that block to not display on the page.

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.