Last active
November 27, 2017 08:25
-
-
Save robincornett/7e6e4aa5317fd89e2cef to your computer and use it in GitHub Desktop.
Responsive menus for HTML5 Genesis themes. with updating skip links. The skip links must follow the pattern established in Genesis core.
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 tag! | |
// Required Scripts and Styles | |
add_action( 'wp_enqueue_scripts', 'leaven_load_scripts', 15 ); | |
function leaven_load_scripts() { | |
// Responsive Navigation | |
wp_enqueue_style( 'fontawesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css', array(), '4.3.0' ); | |
wp_enqueue_script( 'leaven-responsive-menu', get_stylesheet_directory_uri() . '/js/responsive-menu.js', array( 'jquery' ), '1.0.0', true ); | |
$output = array( | |
'mainMenu' => __( 'Menu', 'leaven' ), | |
'subMenu' => __( 'Menu', 'leaven' ), | |
); | |
wp_localize_script( 'leaven-responsive-menu', 'LeavenL10n', $output ); | |
} |
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 tag! | |
// Add skip link needs to secondary nav | |
add_filter( 'genesis_attr_nav-secondary', 'leaven_add_nav_secondary_id' ); | |
function leaven_add_nav_secondary_id( $attributes ) { | |
$attributes['id'] = 'genesis-nav-secondary'; | |
return $attributes; | |
} | |
add_filter( 'genesis_skip_links_output', 'leaven_add_nav_secondary_skip_link' ); | |
function leaven_add_nav_secondary_skip_link( $links ) { | |
$new_links = $links; | |
array_splice( $new_links, 1 ); | |
if ( has_nav_menu( 'secondary' ) ) { | |
$new_links['genesis-nav-secondary'] = __( 'Skip to secondary navigation', 'leaven' ); | |
} | |
return array_merge( $new_links, $links ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Robin,
I've used the code, but now I have no menu at all... any idea of what I could be doing wrong?
I just copied + pasted the code, and removed nothing at all from my original code.
Sorry, I'm not great at .js or .php, so any help is appreciated. :)