Created
July 13, 2012 08:59
-
-
Save Neolot/3103760 to your computer and use it in GitHub Desktop.
WORDPRESS Registering wp_nav_menu() in 3 locations
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
| <?php | |
| // Function for registering wp_nav_menu() in 3 locations | |
| add_action( 'init', 'register_navmenus' ); | |
| function register_navmenus() { | |
| register_nav_menus( array( | |
| 'Top' => __( 'Top Navigation' ), | |
| 'Header' => __( 'Header Navigation' ), | |
| 'Footer' => __( 'Footer Navigation' ), | |
| ) | |
| ); | |
| // Check if Top menu exists and make it if not | |
| if ( !is_nav_menu( 'Top' )) { | |
| $menu_id = wp_create_nav_menu( 'Top' ); | |
| $menu = array( 'menu-item-type' => 'custom', 'menu-item-url' => get_home_url('/'),'menu-item-title' => 'Home' ); | |
| wp_update_nav_menu_item( $menu_id, 0, $menu ); | |
| } | |
| // Check if Header menu exists and make it if not | |
| if ( !is_nav_menu( 'Header' )) { | |
| $menu_id = wp_create_nav_menu( 'Header' ); | |
| $menu = array( 'menu-item-type' => 'custom', 'menu-item-url' => get_home_url('/'), 'menu-item-title' => 'Home' ); | |
| wp_update_nav_menu_item( $menu_id, 0, $menu ); | |
| } | |
| // Check if Footer menu exists and make it if not | |
| if ( !is_nav_menu( 'Footer' )) { | |
| $menu_id = wp_create_nav_menu( 'Footer' ); | |
| $menu = array( 'menu-item-type' => 'custom', 'menu-item-url' => get_home_url('/'), 'menu-item-title' => 'Home' ); | |
| wp_update_nav_menu_item( $menu_id, 0, $menu ); | |
| } | |
| // Get any menu locations that dont have a menu assigned to it and give it on | |
| /* Currently not working. couldnt fix it. | |
| $loc = array('Top', 'Header', 'Footer'); | |
| if ( has_nav_menu( $location )) { | |
| $locations = get_nav_menu_locations(); | |
| return (!empty( $locations[ $location ] )); | |
| } | |
| */ | |
| } | |
| /* Delete nav menu in case you need it | |
| wp_delete_nav_menu( $menu ); | |
| */ | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment