Set multiple menu theme locations using functions on theme install

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:

Read More
$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.

Related posts

Leave a Reply

1 comment

  1. $locations = get_theme_mod( ‘nav_menu_locations’ );

    $adveits_menus = wp_get_nav_menus();

    if ( $adveits_menus ) {
        foreach ( $adveits_menus as $adveits_menu ) {
            if ( $adveits_menu->name == 'Front page EN' ) {
                $locations['menu-1'] = $adveits_menu->term_id;
            } else if ( $adveits_menu->name == 'Front page RU' ) {
                $locations['menu-1___ru'] = $adveits_menu->term_id;
            } else if ( $adveits_menu->name == 'Front page LT' ) {
                $locations['menu-1___lt'] = $adveits_menu->term_id;
            }
        }
    }
    
    set_theme_mod( 'nav_menu_locations', $locations );