Skip to content

Instantly share code, notes, and snippets.

@BinaryMoon
Created August 13, 2018 19:09
Show Gist options
  • Save BinaryMoon/f35e04e012026e873f1bd039add14155 to your computer and use it in GitHub Desktop.
Save BinaryMoon/f35e04e012026e873f1bd039add14155 to your computer and use it in GitHub Desktop.
Label Extra Navigation
<?php
/**
* Plugin Name: Label additional navigation
* Plugin URI: https://prothemedesign.com
* Description: Add an additional navigation position under the header image.
* Author: Ben Gillbanks
* Version: 1.0
* Author URI: https://prothemedesign.com
*
* @package ptd
*/
/**
* Add the additional navigation to the page underneath the header.
* Makes use of WordAds 'before' action hook.
*
* @return void
*/
function label_extra_navigation() {
if ( ! has_nav_menu( 'menu-3' ) ) {
return;
}
?>
<div class="menu-page-container" id="header-menu-2">
<nav class="menu-secondary menu" role="navigation" aria-label="<?php esc_attr_e( 'Header Menu', 'label' ); ?>">
<?php
wp_nav_menu(
array(
'theme_location' => 'menu-3',
'menu_id' => 'nav',
'menu_class' => 'menu-wrap',
'container' => false,
'fallback_cb' => false,
)
);
?>
</nav>
</div>
<?php
}
add_action( 'before', 'label_extra_navigation' );
/**
* Register the new menu.
*
* @return void
*/
function label_after_setup_extra_navigation() {
register_nav_menus(
array(
'menu-3' => esc_html__( 'Header Menu 2', 'label' ),
)
);
}
add_action( 'after_setup_theme', 'label_after_setup_extra_navigation' );
/**
* Duplicate the menu and add it to the slideout drawer so that it is still
* usable responsively.
*
* @return void
*/
function label_copy_extra_menu() {
?>
<script>
;( function( $ ) {
var $menu = $( '#header-menu-2 nav' );
$menu.clone().appendTo( '#menu-drawer' );
} )( jQuery );
</script>
<?php
}
add_action( 'wp_footer', 'label_copy_extra_menu' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment