Hybrid Core comes packaged with a few standard nav menus. These menus are for getting theme developers started. Theme developers may pick and choose which menus they want to support within their theme.
This feature is not meant to include every possible menu in the world. It is a standard list of menus that are common to many WordPress themes. You may choose to use all, some, or none of them. You can even choose to create your own menus using the
register_nav_menu() WordPress function.
This feature only registers menus with WordPress. As a theme developer, it is your responsibility to choose how these menus should be displayed within your theme. If you’re unfamiliar with this process, please read this tutorial on menus.
Registering support for the menus feature
In your theme setup function, add the following line of code.
add_theme_support( 'hybrid-core-menus', array( 'primary', 'secondary' ) );
This will register support for the “Primary” and “Secondary” menus. You can register support for any of the below options. The only important thing to note is that you should try to stick to the conventions laid out below with the default menus.
- Typically located before, within, or after the header area.
- Typically located before, within, or after the header area. However, it should be displayed after the primary menu.
- Typically located before, within, or after the footer area.
So, if you wanted to register support for all the menus, you’d use the following code.
add_theme_support( 'hybrid-core-menus', array( 'primary', 'secondary', 'subsidiary' ) );
Using nav menus in themes
To display a nav menu in your theme, you’d use the
wp_nav_menu() function. Generally, I like to create a completely separate template for individual menus.
Suppose you registered support for the “Primary” menu. In your
header.php (wherever you want to display the menu), add the following line of code.
<?php get_template_part( 'menu', 'primary' ); ?>
Then, create a template named
menu-primary.php. Add the following code to this template.
<?php if ( has_nav_menu( 'primary' ) ) : ?> <div id="menu-primary" class="menu-container"> <?php wp_nav_menu( array( 'theme_location' => 'primary', 'container_class' => 'menu', 'menu_class' => '', 'menu_id' => 'menu-primary-items', 'fallback_cb' => '' ) ); ?> </div><!-- #menu-primary .menu-container --> <?php endif; ?>
What this code does is check if the user has assigned a custom nav menu to the “Primary” location. If so, it displays the menu. You are free to handle this however you like and even change the markup. You’re building a custom theme, so it’s up to you.