Updated on October 14, 2020
In the Genesis Facebook group, a user asked:
This is a question for the Genesis devs here: I’ve noticed that when I create a custom menu location and a custom menu using the wp_nav_menu() function, submenu support isn’t available for those menus. How can I create a custom menu in genesis that has support for submenus?
This members-only tutorial provides the steps to register a custom Custom Menu
navigation theme location and display the menu assigned to it in the site header with proper markup and the corresponding skiplink in Genesis.
Tested in Genesis Sample 3.3.1 with Genesis 3.3.3.
Step 1
Add custom
menu theme location.
Edit config/theme-supports.php
.
Change
'genesis-after-entry-widget-area' => '',
'genesis-footer-widgets' => 3,
'genesis-menus' => [
'primary' => __( 'Header Menu', 'genesis-sample' ),
'secondary' => __( 'Footer Menu', 'genesis-sample' ),
],
to
'genesis-after-entry-widget-area' => '',
'genesis-footer-widgets' => 3,
'genesis-menus' => [
'primary' => __( 'Header Menu', 'genesis-sample' ),
'secondary' => __( 'Footer Menu', 'genesis-sample' ),
'custom' => __( 'Custom Menu', 'genesis-sample' ),
],
Step 2
Add the following at the end of functions.php
.
add_action( 'genesis_header', 'sk_custom_do_nav', 12 );
/**
* Echoes the "Custom Navigation" menu.
*/
function sk_custom_do_nav() {
// Do nothing if menu not supported.
if ( ! genesis_nav_menu_supported( 'custom' ) || ! has_nav_menu( 'custom' ) ) {
return;
}
$class = 'menu genesis-nav-menu menu-custom';
if ( genesis_superfish_enabled() ) {
$class .= ' js-superfish';
}
genesis_nav_menu( array(
'theme_location' => 'custom',
'menu_class' => $class,
) );
}
// Add typical attributes for navigation elements.
add_filter( 'genesis_attr_nav-custom', 'genesis_attributes_nav' );
add_filter( 'genesis_attr_nav-custom', 'sk_skiplinks_attr_nav_custom' );
/**
* Adds ID markup to custom navigation.
*
* @param array $attributes Existing attributes for custom navigation element.
* @return array Amended attributes for custom navigation element.
*/
function sk_skiplinks_attr_nav_custom( $attributes ) {
$attributes['id'] = 'genesis-nav-custom';
return $attributes;
}
add_filter( 'genesis_skip_links_output', 'sk_skip_links_output' );
/**
* Adds skip link for custom navigation.
*
* @param array $links Exiting skiplinks.
* @return array Amended skiplinks.
*/
function sk_skip_links_output( $links ) {
if ( genesis_nav_menu_supported( 'custom' ) && has_nav_menu( 'custom' ) ) {
$links['genesis-nav-custom'] = __( 'Skip to custom navigation', 'genesis' );
}
return $links;
}
Step 3
Let’s add Custom Menu to the list of menus to be combined (having the Primary menu by default) in the mobile menu.
In config/responsive-menus.php
change
return [
'script' => [
'menuClasses' => [
'others' => [ '.nav-primary' ],
],
],
'extras' => [
'media_query_width' => '960px',
],
];
to
return [
'script' => [
'menuClasses' => [
'combine' => [
'.nav-primary',
'.nav-custom',
],
'others' => [ '.nav-primary' ],
],
],
'extras' => [
'media_query_width' => '960px',
],
];
Step 4
Add the following in child theme’s style.css
:
@media only screen and (min-width: 960px) {
.nav-custom .genesis-nav-menu a {
padding-left: 15px;
padding-right: 15px;
}
}
Step 4
At Appearance > Menus > Manage Locations, assign your desired menu in the Custom Menu location.
References
genesis/lib/structure/menu.php
genesis/lib/structure/header.php
genesis/lib/functions/markup.php
Hi Sridhar,
I have tested this tutorial and the Custom Menu location does not show at Appearance > Menus > Manage Locations.
I am using Genesis Sample 2.6.0
Hi,
Just tested and it works fine for me.
If you can send me WordPress login for the site where this is not working via https://sridharkatakam.com/contact/ along with a URL of this tutorial, I can take a look inside and try to advise.
Hi Sridhar,
Apologies for the delay. I have emailed you details.
Kind regards,
Dale
Hi Dale,
I forgot to add a necessary step in the tutorial which was the reason behind the problem.
I have updated the tutorial and added it (Step 1a).
Thanks for bringing this to my attention.
[…] Add Custom Navigation Theme Location in Genesis. […]
Hi Sridhar,
I have followed this tutorial on a fresh Genesis Sample 2.6.0 installation. There seems to be some kind of overlay on the Site Title area removing the ability to click on the Site Title. Even when setting a Logo image; – it is still not clickable.
URL?
https://www.woolpower.co.za/
You should still have testuser login details sent to you via email.
Fixed.
Unless otherwise mentioned, it is expected for users to add suggested code inside functions.php at the bottom.
In this case, I just had to move
below
in your functions.php.
Hi Sridhar,
I appreciate your time on this. It is however not fixed.
Now both Site Title and Primary Nav are not clickable.
You just need to add this CSS:
Hi Sridhar! Another great tutorial!
It works perfect. I like to set this custom menu location in the utility bar right of another tutorial https://sridharkatakam.com/utility-bar-in-genesis-sample/.
Is possible?
Thanks!
I got it! (Almost…)
I changed this line:
add_action( ‘genesis_header’, ‘sk_custom_do_nav’, 12 );
for this:
add_action( ‘genesis_before_utility-bar-right_widget_area’, ‘sk_custom_do_nav’, 12 );
Now, the custom menu shows in “genesis_before_utility-bar-right_widget_area” hook but I can’t show it inline with the widgets in this area itself (for example search widget). I’m missing some hook or something? Some trick with CSS? I think I’m close to achieve it…
Hi!
Very nice tutorial! Thanks!!
could you help me how can i set to custom menu to top of the header? So, i would like to move to the top this custom menu..
How would we add a wrap around the widget area? I used the genesis_after_header hook to add this to a site (https://www.fortenberrylaw.com/), but now the content is full width since it is outside of the header wrap. I need to add a wrap div around the menu, but I can’t figure out how.
I’ve added your custom menu on a site I’m developing for myself, but I want to enclose the menu in a wrapper. How would I do that?
Hello, I don’t think this will work with Genesis 3.3.3. Any updates on this please? Thank you!