Skip to content

Instantly share code, notes, and snippets.

@fahidjavid
Created June 26, 2014 11:14
Show Gist options
  • Save fahidjavid/a279f531abcbd538213c to your computer and use it in GitHub Desktop.
Save fahidjavid/a279f531abcbd538213c to your computer and use it in GitHub Desktop.
How to set WordPress Menus to Theme Locations
<?php
$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