Created
January 18, 2015 19:19
-
-
Save shahadat014/f031551b83acae2a209f to your computer and use it in GitHub Desktop.
Dynamic wordpress menu
This file contains hidden or 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
| Register wordpress menu | |
| add_action('init', 'my_theme_register_menu'); | |
| function my_theme_register_menu() { | |
| register_nav_menu( 'main-menu', 'Main Menu'); | |
| } | |
| // Default menu | |
| function my_theme_default_menu() { | |
| echo '<ul id="nav">'; | |
| if ('page' != get_option('show_on_front')) { | |
| echo '<li><a href="'. home_url() . '/">Home</a></li>'; | |
| } | |
| wp_list_pages('title_li='); | |
| echo '</ul>'; | |
| } | |
| Call menu where you need. | |
| General: | |
| <?php wp_nav_menu(array('theme_location' => 'main-menu', 'menu_id' => 'nav')); ?> | |
| Dynamicaly | |
| <?php | |
| if (function_exists('my_theme_default_menu')) { | |
| wp_nav_menu(array('theme_location' => 'main-menu', 'menu_id' => 'nav', 'fallback_cb' => 'my_theme_default_menu')); | |
| } | |
| else { | |
| my_theme_default_menu(); | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment