Adding Menus in WordPress

To add menus in WordPress, you first need to register them in your functions.php file in your theme. Let’s register two menus: one for the header, and one for the footer.

register_nav_menus( array( 'primary' => 'Header Menu', 'secondary' => 'Footer Menu' ) );

The we can call the WP Menu function in the header and footer.

<nav role="navigation" class="header-nav"> <?php wp_nav_menu( array( 'theme_location' => 'primary' )); ?> </nav>

<nav class="footer-nav"> <?php wp_nav_menu( array( 'theme_location' => 'secondary' )); ?> </nav>

And now you can dynamically add and remove menu items from your WordPress admin area, under Appearance > Menus.

Post a Comment

To post code, use the code tag with a class language-*
Examples: code class="language-markup"code class="language-css"