Skip to content

Instantly share code, notes, and snippets.

@cjkoepke
Last active November 5, 2015 13:50
Show Gist options
  • Save cjkoepke/bacbaa9a5d4a68319dad to your computer and use it in GitHub Desktop.
Save cjkoepke/bacbaa9a5d4a68319dad to your computer and use it in GitHub Desktop.
Add a menu button to the Header, and a "Close Navigation" menu to the Primary Navigation for the off-canvas tutorial. http://www.calvinkoepke.com/add-a-mobile-friendly-off-canvas-menu-in-genesis/
<?php
//* Do NOT include the opening PHP tag
/**
* Add the menu to the .site-header, but hooking right before the genesis_header_markup_close action.
* @author Calvin Koepke (@cjkoepke)
* @link http://www.calvinkoepke.com/add-a-mobile-friendly-off-canvas-menu-in-genesis
*/
add_action( 'genesis_header', 'ck_menu_button', 14 );
function ck_menu_button() {
//* Only add the Menu button if a primary navigation is set. You can switch this for whatever menu you are dealing with
if ( has_nav_menu( "primary" ) ) {
echo '<a alt="Toggle Menu" href="#" class="menu-btn right small">' . __( 'Menu', 'CHILD_THEME_TEXT_DOMAIN' ) . '<span class="dashicons dashicons-menu"></span></a>';
}
}
//* Add the "Close Navigation" text to the Primary menu output.
add_filter( 'genesis_nav_items', 'ck_close_btn', 10, 2 );
add_filter( 'wp_nav_menu_items', 'ck_close_btn', 10, 2 );
function ck_close_btn($menu, $args) {
$extras = '<a href="#" class="close-btn"><em>' . __( 'Close Navigation', 'CHILD_THEME_TEXT_DOMAIN' ) . '</em> <span class="dashicons dashicons-no"></span></a>';
if ( $args->theme_location == "primary" ) {
return $extras . $menu;
} else {
return $menu;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment