
In this WordPress tutorial, I will explain how to:
- Register menu
- Display menu in your theme.
Register menu
Let's say, we want to register / create two menus. One for header and another for footer.
Copy paste below code in functions.php file of your theme.
/**
* Register menus
*/
function register_my_menus() {
register_nav_menus(
array(
'header-menu' => __( 'Header Menu' ),
'footer-menu' => __( 'Footer Menu' )
)
);
}
add_action( 'init', 'register_my_menus' );
Above code will register following two menus.
1) Header Menu
2) Footer Menu
Show menu in theme
To show header-menu in your WordPress theme, add following codes in template file where you wish to show menu like in header.php
<nav class="header-menu">
<?php wp_nav_menu( array( 'theme_location' => 'header-menu' ) ); ?>
</nav>
Similarly, to show footer-menu, use below code.
<nav class="footer-menu">
<?php wp_nav_menu( array( 'theme_location' => 'footer-menu' ) ); ?>
</nav>
Hope this article was helpful to you.
Tutorial Category