There are really only 2 ways to do this in wordpress. The first, which I’ll call the “old way” uses wp_list_pages()
and I would generally not recommend it for menus.
The second, which I would say is much better is using register_nav_menu()
. To use that, add this to the top of your functions.php file.
function register_theme_menus() {
register_nav_menu('main-menu',__( 'Main Menu' ));
}
add_action( 'init', 'register_theme_menus' );
That snippet creates 1 menu called “Main Menu”. You can repeat register_nav_menu()
for as many different menus as you’d like. After adding that you’ll see an option in the WP backend under “Appearance” called “Menus” where you’ll be able to add items to the menu.
To display the menu, call wp_nav_menu(array('menu'=>'main-menu'))
wherever you want to place the menu. Make sure to style it. This creates menus of this format:
<ul class="menu" id="menu-main-menu">
<li class="menu-item"></li>
</ul>
You can add styles to those to style the menu. There is also .current-menu-item
on the li that holds the current page.
There are lots more styles to play with on here, the easiest way to see them all is to create a menu and then “view source” on the menu that was generated.