wp_nav_menu_args is a filter inside wp_nav_menu, which is used to display navigation menus on your site. The $args
parameter passed to the filter is an array containing the wp_nav_menu
arguments. By default they are the following,
$defaults = array(
'menu' => '',
'container' => 'div',
'container_class' => '',
'container_id' => '',
'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' => '',
);
You can find these also in the wp_nav_menu
code reference and in its source code. (These are merged with the theme supplied arguments by wp_parse_args before being passed to the wp_nav_menu_args
filter.)
This means you can use the parameter to check for example which location the filter is currently handling.
add_filter('wp_nav_menu_args', 'my_wp_nav_menu_args_filter');
function my_wp_nav_menu_args_filter($args) {
if ( isset($args['theme_location']) && 'my-theme-location' === $args['theme_location'] ) {
// do something
}
return $args;
}
(For Storefront the location slug is secondary
, which you can find in the source code.)