The script below creates a nav menu and assigns a page to it. Everything's working perfectly except that the nav menu is not being automatically assigned to my theme's "Header-menu" location.
Any ideas why?
//Register menu locations for the theme
add_action( 'init', 'register_my_menus' );
function register_my_menus() {
register_nav_menus(
array('header-menu' => __( 'Header Menu' ), 'footer-menu' => __( 'Footer Menu' ))
);
}
//Create a nav menu, add a page to it and assign it to the theme's "header-menu" location.
$menu_id = wp_create_nav_menu( 'header-menu' );
$menu = array(
'menu-item-type' => 'custom',
'menu-item-url' => get_home_url('/'),
'menu-item-title' => 'Home',
'menu-item-status' => 'publish',
'theme_location' => 'header-menu', //Just a guess but didn't work!!!
);
wp_update_nav_menu_item( $menu_id, 0, $menu );