Last active
February 26, 2019 23:58
-
-
Save NicBeltramelli/f411d714210c27a9b53cb58092178992 to your computer and use it in GitHub Desktop.
Genesis framework add one more responsive navigation menu.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Do NOT include the opening php tag. | |
/** | |
* Add tertiary responsive navigation menu. | |
* | |
* @author Nic Beltramelli | |
*/ | |
/* Rename the default navigation menus add the tertiary menu */ | |
add_theme_support( | |
'genesis-menus', [ | |
'primary' => __( 'Header Right Menu', 'genesis-advanced' ), | |
'secondary' => __( 'Header Left Menu', 'genesis-advanced' ), | |
'tertiary' => __( 'After Header Menu', 'genesis-advanced' ), | |
] | |
); | |
/* Add attributes for navigation elements */ | |
add_filter( 'genesis_attr_nav-custom', 'genesis_attributes_nav' ); | |
/** | |
* Add ID markup to custom navigation | |
* | |
* @param array $attributes Existing attributes for custom navigation element. | |
* @return array Amended attributes for custom navigation element. | |
*/ | |
add_filter( | |
'genesis_attr_nav-custom', function ( $attributes ) { | |
$attributes['id'] = 'genesis-nav-tertiary'; | |
return $attributes; | |
} | |
); | |
/** | |
* Add skip link for tertiary navigation | |
* | |
* @param array $links Exiting skiplinks. | |
* @return array Amended skiplinks. | |
*/ | |
add_filter( | |
'genesis_skip_links_output', function ( $links ) { | |
if ( genesis_nav_menu_supported( 'tertiary' ) && | |
has_nav_menu( 'tertiary' ) ) : | |
$links['genesis-nav-tertiary'] = __( 'Skip to tertiary navigation', 'genesis-advanced' ); | |
endif; | |
return $links; | |
} | |
); | |
/* Reposition the primary navigation menu */ | |
remove_action( 'genesis_after_header', 'genesis_do_nav' ); | |
add_action( 'genesis_header', 'genesis_do_nav', 12 ); | |
/* Reposition the secondary navigation menu */ | |
remove_action( 'genesis_after_header', 'genesis_do_subnav' ); | |
add_action( 'genesis_header', 'genesis_do_subnav', 5 ); | |
/* Display the tertiary menu */ | |
add_action( | |
'genesis_after_header', function () { | |
// Do nothing if menu not supported. | |
if ( ! genesis_nav_menu_supported( 'tertiary' ) || | |
! has_nav_menu( 'tertiary' ) ) : | |
return; | |
endif; | |
$class = 'menu genesis-nav-menu menu-tertiary'; | |
if ( genesis_superfish_enabled() ) : | |
$class .= ' js-superfish'; | |
endif; | |
genesis_nav_menu( | |
[ | |
'theme_location' => 'tertiary', | |
'menu_class' => $class, | |
'container' => 'div', | |
'container_class' => 'wrap', | |
] | |
); | |
}, 10 | |
); | |
/* Define responsive menu settings */ | |
function genesis_advanced_responsive_menu_settings() { | |
$settings = | |
[ | |
'mainMenu' => __( 'Menu', 'genesis-advanced' ), | |
'menuIconClass' => 'dashicons-before dashicons-menu', | |
'subMenu' => __( 'Submenu', 'genesis-advanced' ), | |
'subMenuIconClass' => 'dashicons-before dashicons-arrow-down-alt2', | |
'menuClasses' => | |
[ | |
'combine' => | |
[ | |
'.nav-primary', | |
'.nav-secondary', | |
], | |
'others' => | |
[ | |
'.nav-tertiary', | |
], | |
], | |
]; | |
return $settings; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment