Creating WordPress Custom Menus on the Fly
I'm using this script to create a new custom menu on the fly and assign a page to it...
if ( !is_nav_menu( 'Header Menu' )) {
$menu_id = wp_create_nav_menu( 'Header Menu' );
$menu = array( 'menu-item-type' => 'custom', 'menu-item-url' => get_home_url('/'),'menu-it开发者_运维技巧em-title' => 'Home', 'menu-item-status' => 'publish' );
wp_update_nav_menu_item( $menu_id, 0, $menu );
}
However, what I'm stuck on is how to hook this menu up to my theme's "Menu Locations".
For example, my theme registers a menu location...
register_nav_menus(
array('header-menu' => __( 'Main Navigation Menu' ) )
);
How can I hook the "Header Menu" up to the "Main Navigation Menu" area via script?
ie, I can do this manually from the WordPress "Appearance > Menus" Manager and under "Theme Locations > Main Navigation Menu" I select "Header Menu" and click "Save". I'm trying to do this in script.
This question was answered here > https://wordpress.stackexchange.com/questions/14116/custom-nav-menu-is-created-with-default-pages-but-not-hooked-to-themes-custom-m
精彩评论