Set multiple menu theme locations using functions on theme install


Staff member
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: <a href="" rel="nofollow noreferrer"></a> and this: <a href=""></a> 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-&gt;name == 'ffh' ) {
        $locations['menu'] = $menu-&gt;term_id;
    } else if( $menu-&gt;name == 'ffh' ) {
        $locations['admin'] = $menu-&gt;term_id;
    } else if( $menu-&gt;name == 'ffh' ) {
        $locations['primary'] = $menu-&gt;term_id;
    } else if( $menu-&gt;name == 'ffh-guest' ) {
        $locations['visitor'] = $menu-&gt;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.