Home>Article>CMS Tutorial> How to use wp_nav_menu in wordpress
#How to use wp_nav_menu in wordpress?
wordpress wp_nav_menu usage instructions
Recommended: "wordpress tutorial"
wp_nav_menu() method is located in wp -includes/nav-menu-templates.php file.
Its main purpose is to use this method to
realize the background generation menu call.
Before using this function, the theme 3.0 menu function must be activated.
The method is as follows:
Add
add_theme_support( 'nav-menus' );或者 •// 自定义菜单 •register_nav_menus( •array( •‘header-menu’ => __( ’导航自定义菜单’ ), •‘footer-menu’ => __( ’页角自定义菜单’ ) •) •);
to the functions.php file and simply call it as follows:
The default layout of the called menu is
The code is as follows:
, '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' => , 'depth' => 0, 'walker' => ); ?>
If there are multiple menus, call the following
'menu-header', 'theme_location' => 'primary' ) ) ?>
The menu bar will be generated differently depending on whether you are logged in or not
'logged-in-menu' ) ); } else { wp_nav_menu( array( 'theme_location' => 'logged-out-menu' ) ); } ?>
Remove the menu bar
The menu css style generated byor
'' ) ); ?>
is
. You can add the tags used through
'before' => ,
'after' => ,
'link_before' => ,
'link_after' => ,
and beautify them with css, so that you can get what you want. desired effect.
The above is the detailed content of How to use wp_nav_menu in wordpress. For more information, please follow other related articles on the PHP Chinese website!