How To Add Custom Menus To WordPress Website

2019-04-15 0 Comments Views

Menu management has always been considered a highlight of WordPress, allowing you to control navigation menus flexibly. Through the convenient drag-and-drop interface, free from the limitations of the theme itself, create various combinations of links: internal links, external links, classification, etc., and can embed these custom menus into any location of the theme, feel that WordPress is getting closer and closer to the CMS program.

Of course, all these functions need thematic support. Earlier, I wrote an article on how to support WordPress custom menus. Today I'll teach you how to add more than one custom menu. Take two examples.

register_nav_menus(
array(
'header-menu' => __( 'mainmenu' ),
'footer-menu' => __( 'footmenu' )
)
);

the header-menu and footer-menu are used after the name of the menu (can be arbitrary), the Chinese part will be displayed in the background menu settings page.

2. Add the calling code to the location where you are going to display it.
Usually in header, open header.php and find something similar:

<?php wp_list_pages('depth=2&title_li='); ?>

or

<?php wp_list_categories('title_li=&orderby=id'); ?>

Replaced by:

<?php wp_nav_menu( array( 'theme_location' => 'header-menu' ) ); ?>

or

<?php wp_nav_menu( array( 'theme_location' => 'footer-menu' ) ); ?>

The header-menu and footer-menu are the name of the menu to be invoked, the same as in the first step.
The above two functions can be put in other places, such as sidebar or footer, to see what you like.

3. Define CSS styles appropriately according to different locations.

Related Posts

Maoge

My Wechat: dongyangyemao Email: dongyangyemao#qq.com

Article Comments(0)