Skip to content
All gists
Back to GitHub
Sign in
Sign up
Sign in
Sign up
{{ message }}
Instantly share code, notes, and snippets.
DevShahidul
/
Nave Menu Register
Created
April 26, 2017 14:02
Star
0
Fork
0
Star
Code
Revisions
1
Embed
What would you like to do?
Embed
Embed this gist in your website.
Share
Copy sharable link for this gist.
Clone via HTTPS
Clone with Git or checkout with SVN using the repository’s web address.
Learn more about clone URLs
Download ZIP
Raw
Nave Menu Register
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
Show hidden characters
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>';
}
else{
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
You can’t perform that action at this time.
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.