Home >CMS Tutorial >WordPress >How to create a menu in WordPress

How to create a menu in WordPress

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-07-12 14:21:092780browse

How to create a menu in WordPress

Specific steps to create a menu in wordpress:

First, log in to our wordpress website backend.

How to create a menu in WordPress

Find our appearance in the background and click to enter the editing interface.

How to create a menu in WordPress

Related recommendations: "WordPress Tutorial"

Find the functions.php file in the editing interface and click to open it.

How to create a menu in WordPress

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

How to create a menu in WordPress

Now a menu column appears under our appearance, click to enter the settings menu.

How to create a menu in WordPress

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(            
&#39;theme_location&#39; => &#39;primary&#39;,//register_nav_menus()中指定的主键key,跟后台的菜单相对应        
&#39;container&#39;=> &#39;ul&#39;,//指定导航菜单的最外层包裹元素,可取值为 div 和 nav ;
若不需要该包裹元素可设置其值为false 即可        
&#39;container_class&#39; => &#39;nav-menu&#39;,        
&#39;container_id&#39;=> &#39;&#39;,                   
&#39;menu_id&#39;=>&#39;dropdownmenu&#39;, //菜单ul标签id        
&#39;menu_class&#39; => &#39;&#39;        
));      
?></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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn