How to create Multilevel / Hierarchical menus in WordPress
In WordPress you are able to create a multilevel / hierarchical menu via WordPress Menu System ( WordPress admin -> Appearance -> Menu ) as well as via Theme Customizer ( WordPress admin -> Appearance -> Customize ).
In this documentation we will be looking at the steps to create a multilevel / hierarchical menu.
We will start by looking at the WordPress Menu System.
WordPress Menu System
You can access the WordPress Menu System by logging into your WordPress dashboard, and navigate to Appearance -> Menu.
Set the screen Options
On the right hand, top corner of your screen, you can find the screen options tab.
- Click on it to drop-down and show all available types and properties.
- Check on all the available check-boxes, except the Description check-box.
- Customizr and Customizr Pro Theme, does not support menu description. Therefore, you should leave Description check-box unchecked.
- Click on the create a new menu link.
- Enter your new menu name. In this documentation, we will name it Sample Menu.
- Click on Create Menu button.
Assign Menu Location
Next, we will need to assign menu to it's location.
- Assign Sample Menu to Main Menu ( Theme locations ) by checking on the check-box.
- Click on Save Menu button.
Types Of Menu Items Available
In Customizr and Customizr Pro Theme, there are 6 types of menu items available.
- Pages - They are the pages that you have created.
- Posts - They are the blog posts that you have created.
- Custom Links - You can use this to create a menu item that links to any URL.
- Categories - They are your available categories.
- Tags - They are your available tags.
- Format - They are your available post formats.
Creating Menu Item ( Parent Menu Item )
- In this example we will assign a page, named Sample Page to the menu as a Parent Menu Item.
- Check on the Sample Page check-box, and Click Add to Menu button.
- You will see that it's automatically added to the right hand panel as a menu item.
- Note: This is optional. Normally you do not need to use these steps.
- You can edit the properties of the Sample Page menu item, by clicking on the tiny drop arrow on the right.
- It will expand and show you some text inputs.
- You can enter a Title Attribute, this will only be visible on the front end, when you move your mouse pointer over the menu item and stay there.
- Open link in a new window/tab check-box. You can check on this check-box, if you want the page to open in a new tab or window.
- You can enter CSS Classes to enable special styling of this menu item using custom CSS.
- The Link Relationship ( XFN ) is for adding rel attribute to the menu link. You can refer to this documentation ( Defining relationships with XFN ) for more information on using XFN.
Click on Save Menu button to save all your edits.
Repeat steps 1 to 3 to assign pages, posts ... etc to the menu as Parent Menu item.
- Important Notes:
- Keep your menu as short as possible.
- Speaking from personal experience - Sometimes menu items get lost when you try to save a very large menu. This happen because your posted data is too much for your server to handle.
- A short and organized menu is easily accessible on mobile. Long menu is difficult to access in mobile, because it requires scrolling and not user friendly.
- Normally, we only assign pages to menu, because they are not accessible unless we tag it to the menu.
- We do not assign posts to menu, because they are accessible via your Home page or Posts page.
- Keep your menu as short as possible.
By now you should have a few Parent Menu Items.
Create Sub Menu Items
Now we can proceed to create sub menu items. Looking at the previous screenshot, you can see that there is a page named Level 1. We will be adding a few sub menu items to it.
- Select pages that you want to use as sub menu item and add them to the menu area.
- In this example we will add Level 2a, 2b, and Level 3a, 3b pages.
- Check on their check box and click Add to Menu button.
- You will see that they are added to the Menu Structure on the right.
WordPress menu system supports drag and drop. Therefore, you are able to click and hold a menu item, drag it to a new position before releasing the mouse button to drop it in place.
- You can start dragging the sub Level pages into their position.
- Drag Level 2a and place it under Level 1 and slightly to the right, this will indicate that it's a sub menu item of Level 1.
- Drag Level 2b directly underneath Level 2a, this will indicate that it's a sub menu item of Level 1, but on the same level as Level 2a.
- Now we can create a third level, by dragging Level 3a and place it under Level 2b and slightly to the right, this will indicate that it's a sub menu item of Level 2b.
- Drag Level 3b directly underneath Level 3a, this will indicate that it's a sub menu item of Level 2b, but on the same level as Level 3a.
- Look at the following screenshot to have a better understanding.
- Click on Save Menu to save your setup.
- That's all for using the WordPress Menu System to setup your menu.
Next, we will proceed to look at how to use the WordPress Theme Customizer to setup your menu structure.
Login to your WordPress dashboard and navigate to WordPress admin -> Appearance -> Customize -> Menus.
- Click on the + Add a menu button.
- Enter a menu name, in this example we will call our menu, Sample Menu 2
Click on Create Menu button and you will see the following screenshot.
Check on the Main Menu check box to assign Sample Menu 2 to the Main Menu, then click on + Add Items button. The section to select menu item will slide out.
Add Menu Items
Click on Page, it will drop-down to let you select your pages that you want to add to menu structure.
Click on the pages that you want to add to your menu, they will be automatically added to the menu structure on the left.
Arrange Menu Items
- We can now begin arranging the menu items into multi-level.
- Click on the word Reorder, controls will appear for you to re-arrange them.
Click on the arrows up, down, left, right for each menu item, to arrange them into multi-level.
We are done now. Click on Save and Publish button.
- You can proceed to manage your header menus.