Skip to content

Instantly share code, notes, and snippets.

@mharis
Created October 13, 2013 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mharis/6968473 to your computer and use it in GitHub Desktop.
Save mharis/6968473 to your computer and use it in GitHub Desktop.
How to set WordPress Menus to Theme Locations
$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