Skip to content

Instantly share code, notes, and snippets.

Created April 26, 2017 14:02
What would you like to do?
1. Register menu in function
// Register navigation
function register_theme_menu(){
register_nav_menus(array( // Using array to specify more menus if needed
'main_menu' => 'Main menu',
'footer_menu' => 'Footer Menu'
add_action('init', 'register_theme_menu');
2. Creat fallback menu in function
// Custom nav fallback function
function theme_default_menu(){
echo '<nav class="main-nav">';
if(is_user_logged_in() ) {
echo '<ul><li><a href="'. home_url() . '/wp-admin/nav-menus.php">Create a Menu</a></li></ul>';
echo '<ul><li><a href="'. home_url() . '/">Home</a></li></ul>';
echo '</nav>';
3. Calling registered Menu
// Calling manu in html
<?php wp_nav_menu(array(
'theme_location' => 'main_menu',
'menu_class' => 'main-nav-ul',
'container_class' => 'main-nav',
'fallback_cb' => 'theme_default_menu',
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment