By default, there are one to two menus in your WordPress themes. Sometime you need to create more menus to show navigation to your site. For example: Top menu, Main menu, Left menu, Right menu, Bottom menu, Footer menu, ect…
This post will help you how to register menus in our WordPress theme by using PHP function to create or register new menu in functions.php, in your WordPress theme, then set new menu item in the Appearance -> Menu, checking menu location that you registed
Register New Menus
Insert bellow code to functions.php file
// Custom Register Menus function register_main_menus() { register_nav_menus( array( 'header-menu' => __( 'Header Menu' ), 'sidebar-menu' => __( 'Sidebar Menu' ), 'bottom-menu' => __( 'Bottom Menu' ), ) ); }
Create new menu item
Login to WordPress Dashboard Admin and do step by step
- Choose Dashboard -> Appearance -> Menus
- Create A new Menu and insert Menu item
- Check Theme locations, choose position which you like
Display your menu on WordPress theme
Open header.php file in your folder theme and insert code bellow to position which you want
<?php wp_nav_menu( array( 'theme_location' => 'header-menu' ) ); ?>
You can replace header-menu with WordPress-readable name you choose
Custom Menu class
You can custom CSS for your menu with class header_menu_class
<?wp_nav_menu( array( 'theme_location' => 'header-menu', 'container_class' => 'header_menu_class' ) ); ?>
Thanks for reading.