I have a network of wordpress sites, some of them need to install an alternative theme with additional functionality. The original theme has 4 menu locations, and I would like to set these when the new theme is installed.
I used this: http://mharis.net/how-to-set-wordpress-menus-to-theme-locations/ and this: https://wordpress.stackexchange.com/questions/15455/how-to-hard-code-custom-menu-items as a base and have this:
$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 == 'ffh' ) {
$locations['menu'] = $menu->term_id;
} else if( $menu->name == 'ffh' ) {
$locations['admin'] = $menu->term_id;
} else if( $menu->name == 'ffh' ) {
$locations['primary'] = $menu->term_id;
} else if( $menu->name == 'ffh-guest' ) {
$locations['visitor'] = $menu->term_id;
}}}
set_theme_mod('nav_menu_locations', $locations); // set menus to locations
}
add_action('menu_location_register' );
But it’s not working. I’d appreciate any suggestions.
$locations = get_theme_mod( ‘nav_menu_locations’ );
$adveits_menus = wp_get_nav_menus();