Set multiple menu theme locations using functions on theme install

admin

Administrator
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="http://mharis.net/how-to-set-wordpress-menus-to-theme-locations/" rel="nofollow noreferrer">http://mharis.net/how-to-set-wordpress-menus-to-theme-locations/</a> and this: <a href="https://wordpress.stackexchange.com/questions/15455/how-to-hard-code-custom-menu-items">https://wordpress.stackexchange.com/questions/15455/how-to-hard-code-custom-menu-items</a> as a base and have this:

Code:
$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.