PHP WordPress Navigation Menu

Feb 23, 2023

There is a function in WordPress that displays a navigation menu on your website – wp_nav_menu().

By default, it displays the menu assigned to the “Primary” location in the WordPress dashboard, but you can specify a different menu or customize the output by passing various arguments to the function.

Here is an example of how you might use wp_nav_menu() in your theme’s template file:

<?php $args = array( 'theme_location' => 'primary', 'container' => 'nav', 'container_class' => 'main-nav', 'menu_class' => 'menu', 'depth' => 2, ); wp_nav_menu( $args ); ?>

This will display the menu assigned to the “Primary” location, wrapped in a nav element with a class of main-nav, and with each menu item contained in a list element with a class of menu. The depth argument specifies how many levels of the menu hierarchy to display.

You can find more information about wp_nav_menu() and the available arguments in the WordPress documentation:

Ready to start?

Contact our CTO or fill out the form

    By entering your email, you agree with our Terms of use and Privacy policy