wp-includes/nav-menu-template.php:57Displays a navigation menu.
$argsarrayoptionalarray()$menuint|string|WP_Termdefault: empty
$menu_classstringdefault: 'menu'
$menu_idstringdefault: is the menu slug, incremented
$containerstringdefault: 'div'
$container_classstringdefault: 'menu-{menu slug}-container'
$container_idstringdefault: empty
$container_aria_labelstringdefault: empty
$fallback_cbcallable|falsedefault: is 'wp_page_menu'. Set to false for no fallback
$beforestringdefault: empty
$afterstringdefault: empty
$link_beforestringdefault: empty
$link_afterstringdefault: empty
$echobooldefault: true
$depthintdefault: 0. Default 0
$walkerobjectdefault: empty
$theme_locationstring
$items_wrapstringdefault: is a ul with an id and class
$item_spacingstringdefault: 'preserve'
void|string|false7 hooks fire while wp_nav_menu() runs, in this order:
Filters the arguments used to display a navigation menu.
Filters whether to short-circuit the wp_nav_menu() output.
Filters the list of HTML tags that are valid for use as menu containers.
Filters the sorted list of menu item objects before generating the menu's HTML.
Filters the HTML list content for navigation menus.
Filters the HTML list content for a specific navigation menu.
Filters the HTML content for navigation menus.
function wp_nav_menu( $args = array() ) { static $menu_id_slugs = array(); $defaults = array( 'menu' => '', 'container' => 'div', 'container_class' => '', 'container_id' => '', 'container_aria_label' => '', 'menu_class' => 'menu', 'menu_id' => '', 'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>', 'item_spacing' => 'preserve', 'depth' => 0, 'walker' => '', 'theme_location' => '', ); $args = wp_parse_args( $args, $defaults ); if ( ! in_array( $args['item_spacing'], array( 'preserve', 'discard' ), true ) ) { // Invalid value, fall back to default. $args['item_spacing'] = $defaults['item_spacing']; } /** * Filters the arguments used to display a navigation menu. * * @since 3.0.0 * * @see wp_nav_menu() * * @param array $args Array of wp_nav_menu() arguments. */ $args = apply_filters( 'wp_nav_menu_args', $args ); $args = (object) $args; /** * Filters whether to short-circuit the wp_nav_menu() output. * * Returning a non-null value from the filter will short-circuit wp_nav_menu(), * echoing that value if $args->echo is true, returning that value otherwise. * * @since 3.9.0 * * @see wp_nav_menu() * * @param string|null $output Nav menu output to short-circuit with. Default null. * @param stdClass $args An object containing wp_nav_menu() arguments. */ $nav_menu = apply_filters( 'pre_wp_nav_menu', null, $args ); if ( null !== $nav_menu ) { if ( $args->echo ) { echo $nav_menu; return; } return $nav_menu; } // Get the nav menu based on the requested menu. $menu = wp_get_nav_menu_object( $args->menu ); // Get the nav menu based on the theme_location. $locations = get_nav_menu_locations(); if ( ! $menu && $args->theme_location && $locations && isset( $locations[ $args->theme_location ] ) ) { $menu = wp_get_nav_menu_object( $locations[ $args->theme_location ] ); } // Get the first menu that has items if we still can't find a menu. if ( ! $menu && ! $args->theme_location ) { $menus = wp_get_nav_menus(); foreach ( $menus as $menu_maybe ) {Introduced in 3.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
src/wp-includes/nav-menu-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.