Created
October 13, 2013 23:20
-
-
Save mharis/6968473 to your computer and use it in GitHub Desktop.
How to set WordPress Menus to Theme Locations
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
$locations = get_theme_mod( 'nav_menu_locations' ); // registered menu locations in theme | |
$menus = wp_get_nav_menus(); // registered menus | |
if($menus) { | |
foreach($menus as $menu) { // assign menus to theme locations | |
if( $menu->name == 'Main' ) { | |
$locations['main_navigation'] = $menu->term_id; | |
} else if( $menu->name == '404' ) { | |
$locations['404_pages'] = $menu->term_id; | |
} else if( $menu->name == 'Top' ) { | |
$locations['top_navigation'] = $menu->term_id; | |
} | |
} | |
} | |
set_theme_mod('nav_menu_locations', $locations); // set menus to locations |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment