Instantly share code, notes, and snippets.
Last active
May 3, 2020 01:03
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save dotherightthing/28a138e2a758c0aa37d16bbde0c609c5 to your computer and use it in GitHub Desktop.
Register menus #wordpress #library
This file contains hidden or 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
/** | |
* Display footer navigation. | |
* This is a duplicate of header navigation, | |
* which is shown on mobile devices | |
* when JS is disabled. | |
* | |
* @see Ex https://github.com/dotherightthing/wpdtrt/template-parts/navigation/navigation-footer.php | |
* @see https://github.com/dotherightthing/wpdtrt-responsive-nav | |
*/ | |
?> | |
<nav role="navigation" aria-label="<?php esc_attr_e( 'Footer 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', // intentional duplicate to use same source. | |
'container' => 'div', | |
'container_class' => '', | |
'container_id' => 'footer-nav', | |
'menu_class' => 'navigation', | |
'menu_id' => '', | |
'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. | |
* | |
* @todo why does this work when the full text is "Footer Menu (mobile-first noscript fallback)" | |
*/ | |
'theme_location' => 'Footer Menu', | |
) ); | |
?> | |
</nav> |
This file contains hidden or 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
/** | |
* 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> |
This file contains hidden or 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
/** | |
* 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