apply_filters( 'wp_nav_menu_args', array $args )

Filters the arguments used to display a navigation menu.


Description Description

See also See also


Top ↑

Parameters Parameters

$args

(array) Array of wp_nav_menu() arguments.


Top ↑

More Information More Information

The “wp_nav_menu_args” filter is applied to the arguments of the wp_nav_menu() function before they are processed.

This filter can be used in functions.php of a child theme to add/remove/modify the arguments of a menu defined in the parent theme.

Also, plugins can use this filter to change menus by adding classes/IDs or using a custom walker object.


Top ↑

Source Source

File: wp-includes/nav-menu-template.php

View on Trac



Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by megamenu

    The following code will populate the “theme_location” option if it was not specified (or was left empty) in the initial call to “wp_nav_menu”.

    function wp_nav_menu_populate_missing_theme_location( $args ) {
    	if ( ! isset( $args['theme_location'] ) || $args['theme_location'] == "" ) {
    		$args['theme_location'] = 'main_navigation';
    	}
    	
    	return $args;
    }
    add_filter( 'wp_nav_menu_args', 'wp_nav_menu_populate_missing_theme_location' );
  2. Skip to note 2 content
    Contributed by stevenlinx

    Example migrated from Codex:

    The Twenty Thirteen theme defines the following menu in its header.php file.

    <?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) ); ?>
    

    The following example code will add an ID to the container and change the “depth” to -1 so that links at all levels are displayed in a single, flat list.

    add_filter( 'wp_nav_menu_args', 'modify_nav_menu_args' );
    
    function modify_nav_menu_args( $args )
    {
    	if( 'primary' == $args['theme_location'] )
    	{
    		$args['depth'] = -1;
    		$args['container_id'] = 'my_primary_menu';
    	}
    
    	return $args;
    }
    

    The container ID will only show up if you set a menu for this theme location.

You must log in before being able to contribute a note or feedback.