How to Create Menus and Define Menu Links in Drupal
Menus in Drupal are a powerful way to manage the navigation structure of your website. They help organize your site's content and improve user experience. In this blog post, we will walk through the steps to create a menu, define menu links, and add sub-menu items in Drupal.
Step 1: Creating a New Menu
- Log in to your Drupal site: Use your administrative credentials to log in.
- Navigate to the Menus page:
- In the admin toolbar, go to Structure > Menus.
Add a new menu:
- Click on the Add menu button.
- Fill in the required fields:
- Menu name: Enter a name for your menu. This will be used internally.
- Administrative summary: Optionally, add a description for the menu.
Click on the Save button to create the menu.
Step 2: Adding Menu Links
- Access the menu:
- From the Menus page, find your newly created menu and click on its Edit menu link.
- Add a menu link:
- Click on the Add link button.
- Fill in the required fields:
- Menu link title: Enter the text that will be displayed as the link.
- Link: Enter the path for the link. This can be an internal path (e.g.,
/node/1
) or an external URL (e.g.,https://example.com
). - Description: Optionally, add a description that will appear when users hover over the link.
- Enabled: Check this box to make the link active.
- Click on the Save button to add the menu link.
Step 3: Adding Sub-menu Items
- Navigate to the menu:
- Go to Structure > Menus, and click on the Edit menu link for the menu where you want to add sub-menu items.
- Add a sub-menu link:
- Click on the Add link button.
- Fill in the required fields as before:
- Menu link title
- Link
- Description
- Enabled
- Parent link: To create a sub-menu item, select the parent link from the Parent link dropdown. This will nest the new link under the selected parent.
- Click on the Save button to add the sub-menu link.
Step 4: Managing Menu Structure
- Reordering menu items:
- Navigate to the Edit menu page of the desired menu.
- Use the drag-and-drop handles to reorder menu items. This allows you to change the order and hierarchy of links and sub-menu items.
- Click on the Save configuration button to apply changes.
- Editing or deleting menu items:
- To edit a menu item, click the Edit link next to the item you want to change, make the necessary changes, and click Save.
- To delete a menu item, click the Delete link next to the item, and confirm the deletion.
Step 5: Displaying the Menu
- Add the menu block to a region:
- Go to Structure > Block layout.
- Find the region where you want to place the menu and click on the Place block button.
- In the block placement dialog, find your menu block and click the Place block button next to it.
- Configure the block settings as needed, and click on the Save block button.
- Configure menu settings:
- Depending on your theme, you may need to adjust settings to display the menu correctly.
- Go to Appearance > Settings for your theme, and check the menu settings.
Conclusion
Creating and managing menus in Drupal is straightforward and enhances your website's navigation. By following these steps, you can create menus, define menu links, and organize sub-menu items to improve the user experience on your site.
Happy Drupaling!