Site Building
Topic

Menus for Drupal 7, 8, 9, 10, and 11

Drupal's menu system allows users to create as many separate menus as they need throughout their site. Links can be created to both external sites and internal pieces of content. The site administration interface gives users (with sufficient permissions) the ability to organize and sort these links within their respective menus. The API provided by the menu system gives developers the ability to interact with and alter menu links. The API also includes a mechanism to provide menu links from within custom modules.

Example tasks

  • Create several menus for use (and display) in various locations throughout a site
  • Add a link to a menu from within a custom module
  • Understand how existing menu items can be altered

Confidence

The Drupal menu system is stable in core.

Drupalize.Me resources

Configuring menus

Drupal 8, 9, 10, and 11
More information

Overview of the menu concept and menus automatically created with the core Standard installation profile.

More information

How to add a page to the navigation.

More information

How to reorder links in a menu.

Menus can be added as menu blocks using the Block display system

Blocks

Topic
Drupal 7, 8, 9, 10, and 11
More information

A block is a reusable widget that is placed inside regions (layout containers) of your theme. Blocks can be used by site administrators on the Block layout admin page or provided by a module using the Plugin API.

For developers

From the Develop Custom Pages guide:

From the Drupal Module Developer Guide:

Categories
Drupal 8, 9, 10, and 11
More information

Drupal offers module developers several methods for creating different types of links, all defined by module configuration. This tutorial explores these types of links, how they relate to each other, and when to use them.

In this tutorial, we'll learn:

  • The nature of menu items, action links, and local task links.
  • Examples of each link type in Drupal's UI and their application in our scenario.
  • Criteria for selecting the appropriate link type for adding the weather page to site navigation.

By the end of this tutorial, you'll understand the different types of links in Drupal and how they apply to adding navigational elements for custom module pages.

Categories
Drupal 8, 9, 10, and 11
More information

Drupal's Menu system allows module developers to define navigational links, offering flexibility to site builders for configuration and arrangement. By linking to routes rather than URLs, these links remain functional, even when route definitions change.

In this tutorial, we'll:

  • Create a MODULE_NAME.links.menu.yml file.
  • Define a new menu item link for the /weather page in our anytown module.
  • Configure Drupal to display the link in the primary navigation.

By the end of this tutorial, you'll be able to define new menu item links and integrate them into your site's configuration.

Drupal 7

More information

Provides a overview presentation for how Drupal's menu system takes care of incoming requests via the index.php. Then it walks through the process of implementing a simple module that hooks into Drupal's menu system at the path of /magic. It then executes a page callback function of menu_magic_basic(), which outputs some simple markup text.

Additional resources

hook_menu() documentation

This tutorial is part of our Module Developer in Drupal 7 series. Several of the tutorials that follow this one walk through some of the more advanced techniques for working with the menu system.

More information

In this video we take a tour of Drupal menus, and show you how you can modify existing menu items and create your own.

Guides

Not sure where to start? Our guides provide useful learning tracks for all skill levels.

Navigate guides

External resources

  • Accessible Navigation with Drupal Core's Menu System (lullabot.com)
    • New to Drupal 8.9 and 9.0 is the ability to create the HTML <button> element within a native Drupal menu that can be used to toggle secondary menus (such as drop-downs or mega-menus) in a usable and accessible way. Learn more in this article from Lullabot by front-end developer Mike Herschel.