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.
3 Answers
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; ?>
-
3I think its better if you put this snippet in template.php on the hook_preprocess_page. Just to follow the Drupal Standards.– yvanCommented Aug 25, 2011 at 5:38
-
1I actually started in template_preprocess_page, but always ended up with a WSOD for some reason.– JukeboxCommented Aug 25, 2011 at 5:48
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.
I ended up putting the home link in a separate menu/block, then set that block to not display on the page.