2

In my sitemap, I am displaying main menu and footer menu, but as per requirement I don't want a specific menu item to display in the sitemap. My footer menu has following items:

  • industrial
  • mechanics
  • sports

Is there a way not to add mechanics to the sitemap?

1

Maybe you want to consider the approach described in comment # 1 in issue # 985138 (for D7), which is like so:

/**
* Override site_map function
*/
function hide_in_sitemap_preprocess_site_map(&$variables) {
  $mids = variable_get('site_map_show_menus', array());
  $output = '';
  if ($mids) {
    foreach ($mids as $mid) {
      $menu = menu_load($mid);
      // Use menu_tree_all_data to retrieve the expanded tree.
      $tree = menu_tree_all_data($mid);
        foreach ($tree as $branch => $value) {
          if ($value["link"]["options"]["hide_in_sitemap"]) {
            unset($tree[$branch]);
        }
      }

      if (module_exists('i18nmenu')) {
        i18nmenu_localize_tree($tree);
      }
      $menu_display = _site_map_menu_tree_output($tree);
      $rendered = drupal_render($menu_display);

      if (!empty($menu_display)) {
        $title = $menu['title'];
          $vars = array( 'title' => $title,
                        'content' => $rendered);
        $output .= theme('site_map_box', $vars);
      }
    }
  }
  $variables["menus"] = $output;
}
1

If you just don't want to display the link, a quick and dirty workaround with a little help from css could look like this:

li.menu-id_number  {
    display:none;
}

so for a page of content type "sitemap" and a menu link with an id number of "1234" this could look like this:

.page-sitemap li.menu-1234  {
    display:none;
}
0

You can do this by using Menu Item visibility module.

This module exposes configurable and extendable visibility settings for menu links. For example, if you want to create a 'My account' link that points to /user, both anonymous and registered users have access to the /user path, so both will see the link, even if anonymous users do not technically have an account. Using this module will allow you to only have your 'My account' link visible to registered users, and hide it from anonymous users.

  • Thanku @NishantP, if I used this to hide a specific item then it will be hidden from my main menu too whereas I need to only hide it from sitemap display..Strange client requirement :( – nomeer May 19 '15 at 12:53
  • No by using this module you can hide item on particular page. – Nishant May 19 '15 at 12:59
  • It gives me visibility options for only roles, anonymous user, authenticate user then how can I exclude it only from sitemap page. If a selected anyone option then it will excluded from my main menu too. – nomeer May 19 '15 at 13:16

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.