WordPress V4.0+Template Tag Reference Guide as of Version 4.2
Presented by DBS > Interactive Development :
Navigation Menu Tags
WP Navigation Menu wp_nav_menu();
Displays a navigation menu created in the Appearance > Menus panel. Given a theme_location parameter, the function displays the menu assigned to that location, or nothing if no such location exists or no menu is assigned to it. If not given a theme_location parameter, the function displays the menu matching the ID, slug, or name given by the menu parameter, if that menu has at least 1 item; otherwise, the first non-empty menu; otherwise, output of the function given by the fallback_cb parameter (wp_list_pages(), by default); otherwise nothing. Arguments are passed in as either an array or a query string.
$args = array( | ||||
'theme_location' | => | '', | ||
'menu' | => | '', | ||
'container' | => | 'div', | ||
'container_class' | => | 'menu-{menu slug}-container', | ||
'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>', | ||
'depth' | => | 0, | ||
'walker' | => | '' | ||
); |
<?php wp_nav_menu($args); ?>
theme_location
String • Default: none
(Optional) the location in the theme to be used--must be registered with register_nav_menu() in order to be selectable by the user.
menu
String • Default: none
(Optional) The menu that is desired; accepts (matching in order) id, slug, name.
container
String • Default: 'div'
(Optional) Whether to wrap the ul, and what to wrap it with. Allowed tags are div and nav. Use false for no container
container_class
String • Default: 'menu-{menu slug}-container'
(Optional) the class that is applied to the container.
container_id
String • Default: none
(Optional) The ID that is applied to the container.
menu_class
String • Default: 'menu'
(Optional) CSS class to use for the ul element which forms the menu.
menu_id
String • Default: menu slug, incremented
(Optional) The ID that is applied to the ul element which forms the menu.
echo
Boolean • Default: true
(Optional) Whether to echo the menu (true) or return it for use in PHP (false).
fallback_cb
String • Default: 'wp_page_menu'
(Optional) If the menu doesn't exist, the fallback function to use. Passes $args to the custom function. Set to false for no fallback.
before
String • Default: none
(Optional) Output text before the <a> of the link.
after
String • Default: none
(Optional) Output text after the <a> of the link.
link_before
String • Default: none
(Optional) Output text before the link text.
link_after
String • Default: none
(Optional) Output text after the link text.
items_wrap
String • Default: none
(Optional) Whether to wrap the items with a <ul>, and what to wrap them with
depth
Integer • Default: 0
(Optional) How many levels of the hierarchy are to be included where 0 means all.
walker
Object • Default: new Walker_Nav_Menu
(Optional) Custom walker object to use (Note: You must pass an actual object to use, not a string).
WP Navigation Menuswp_nav_menus();
Displays navigation menus created in the Appearance > Menus panel. Given a theme_location parameter, the function displays the menus assigned to that location, or nothing if no such location exists or no menu is assigned to it. If not given a theme_location parameter, the function displays the menu matching the ID, slug, or name given by the menu parameter, if that menus has at least 1 item; otherwise, the first non-empty menu; otherwise, output of the function given by the fallback_cb parameter (wp_list_pages(), by default); otherwise nothing. Arguments are passed in as either an array or a query string.
register_nav_menus( array( | ||||
'pluginbuddy_mobile' | => | 'PluginBuddy Mobile Navigation Menu', | ||
'footer_menu' | => | 'My Custom Footer Menu', | ||
) ); |
<?php register_nav_menus( $locations ); ?>
Get Registered Nav Menusget_registered_nav_menus();
Returns an array of all registered navigation menus in a theme.
$menus = get_registered_nav_menus(); | ||||
foreach ( $menus as $location => $description ) { | ||||
echo $location . ': ' . $description . ' '; | ' | |||
} |
<?php get_registered_nav_menus(); ?>
List Nav Menu Itemswalk_nav_menu_tree();
Retrieve the HTML list content for nav menu items.
<?php walk_nav_menu_tree($items, $depth, $r); ?>
$items
Array • Default: None
(Required)
$depth
Integer • Default: None
(Required)
$r
Object • Default: None
(Required)