Home > Article > CMS Tutorial > How to create a menu in WordPress
Specific steps to create a menu in wordpress:
First, log in to our wordpress website backend.
Find our appearance in the background and click to enter the editing interface.
Related recommendations: "WordPress Tutorial"
Find the functions.php file in the editing interface and click to open it.
Add the following code between:
if (function_exists('register_nav_menus')) { register_nav_menus(array( //主键key调用nav时使用,值value为后台菜单显示名称 'primary' => 'Primary Navigation' )); }
Then click to update the file
Now a menu column appears under our appearance, click to enter the settings menu.
Click to create a menu, then select the items to add to the menu, and then click to save the menu.
Now that our menu is set up, how to call it? Where you need to call the menu, add the following code
<div id="menu"><?php wp_nav_menu(array( 'theme_location' => 'primary',//register_nav_menus()中指定的主键key,跟后台的菜单相对应 'container'=> 'ul',//指定导航菜单的最外层包裹元素,可取值为 div 和 nav ; 若不需要该包裹元素可设置其值为false 即可 'container_class' => 'nav-menu', 'container_id'=> '', 'menu_id'=>'dropdownmenu', //菜单ul标签id 'menu_class' => '' )); ?></div> 然后就完成菜单的调用了
Notes
It is recommended to use pages or categories for custom menus in wordpress
The above is the detailed content of How to create a menu in WordPress. For more information, please follow other related articles on the PHP Chinese website!