Wordpress theme, adding an extra menu

<?php if ( function_exists('has_nav_menu') && has_nav_menu('primary-menu') ) { wp_nav_menu( array( 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_id' => 'main-nav', 'menu_class' => 'nav fl', 'theme_location' => 'primary-menu' ) ); } else { ?> 

I am trying to add a secondary menu from the Wordpress control menu in my functions.php my child theme for Woothemes Canvas . I find the way to add it to the array above, but I cannot get it to work. Thoughts?

+4
source share
2 answers

Jason, you first need to register your "new" (secondary) menu with register_nav_menu () as:

 add_action( 'init', 'register_my_menu' ); function register_my_menu() { register_nav_menu( 'secondary-menu', __( 'Secondary Menu' ) ); } 

You do this in your theme functions.php file.

Then you can call this menu in the template files. To use your code above, you probably want something like:

 if ( function_exists('has_nav_menu') && has_nav_menu('secondary-menu') ) { wp_nav_menu( array( 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_id' => 'secondary-nav', 'menu_class' => 'nav fl', 'theme_location' => 'secondary-menu' ) ); } 

or maybe

 if ( function_exists('has_nav_menu') && has_nav_menu('primary-menu') && has_nav_menu('secondary-menu') ) { wp_nav_menu( array( 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_id' => 'main-nav', 'menu_class' => 'nav fl', 'theme_location' => 'primary-menu' ) ); wp_nav_menu( array( 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_id' => 'secondary-nav', 'menu_class' => 'nav fl', 'theme_location' => 'secondary-menu' ) ); } 

The second displays both menus, if both exist, the first is likely to be used in addition to the one you posted in your original question.

+5
source

But in my case, I did not use the init action, just put the menu register function in my child theme function.php file

 register_nav_menu( 'footer', 'Footer Menu' ); 
0
source

Source: https://habr.com/ru/post/1336638/


All Articles