Skip to content

Instantly share code, notes, and snippets.

@dotherightthing
Last active May 3, 2020 01:03
Show Gist options
  • Save dotherightthing/28a138e2a758c0aa37d16bbde0c609c5 to your computer and use it in GitHub Desktop.
Save dotherightthing/28a138e2a758c0aa37d16bbde0c609c5 to your computer and use it in GitHub Desktop.
Register menus #wordpress #library
/**
* Display top navigation.
*
* @see Ex https://github.com/dotherightthing/wpdtrt/template-parts/navigation/navigation-header.php
* @see https://github.com/dotherightthing/wpdtrt-responsive-nav
*/
?>
<nav role="navigation" aria-label="<?php esc_attr_e( 'Header Menu', 'wpdtrt' ); ?>">
<?php
/**
* Navigation menu
* wp_page_menu: 2.7.0+
* wp_nav_menu: 3.0.0+
*/
wp_nav_menu( array(
/**
* Apply Appearance > Menus > Menu Structure
* otherwise fallback_cb is used
*/
'menu' => 'header-menu',
'container' => 'div',
'container_class' => '',
'container_id' => '',
'menu_class' => 'navigation',
'menu_id' => 'header-nav',
'echo' => true,
/**
* The wp_page_menu() is sorted alphabetically
*/
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'item_spacing' => 'preserve',
'depth' => 0,
'walker' => '',
/**
* Theme location must be registered with register_nav_menu()
* in order to be selectable by the user.
*/
'theme_location' => 'Header Menu',
) );
?>
</nav>
/**
* Pluggable
* Allow child themes to replace this function with their own
*
* @see https://github.com/dotherightthing/wpdtrt-responsive-nav
*/
if ( ! function_exists( 'wpdtrt_register_menus' ) ) {
add_action( 'init', 'wpdtrt_register_menus' );
/**
* Register Menus
* This sets the name that will appear at Appearance -> Menus.
* Add locations to Menu settings > Display location, and the Manage Locations tab
*
* @link https://developer.wordpress.org/themes/functionality/navigation-menus/#register-menus
*/
function wpdtrt_register_menus() {
register_nav_menus(
array(
// menu location slug => description.
'header-menu' => __( 'Header Menu', 'wpdtrt' ),
'footer-menu' => __( 'Footer Menu (mobile-first noscript fallback)', 'wpdtrt' ),
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment