Agus's solution is close but not quite there yet. I want to be able to programmatically create several (say 2) theme locations, then create 2 menus and assign them to the specific locations of my choice.
Then I want to create pages and assign them to the menus of my choice.
I've spent hours looking at blog posts, WordPress Docs and the WordPress source code.
So far I have compiled:
//Create a Page (home page in this case)
global $user_ID;
$home_page = array(
'post_type' => 'page',
'post_name' => 'home',
'post_title' => 'Home',
'post_content' => '<h1>Hello there!</h1>',
'menu_order' => 0,
'post_status' => 'publish',
'comment_status' => 'closed',
'ping_status' => 'closed',
);
wp_insert_post( $home_page );
// Register menu locations
function register_my_menus() { register_nav_menus(
array( 'header' => __( 'Header Menu' ), 'footer' => __( 'Footer Menu' ))
); }
add_action( 'init', 'register_my_menus' );
// Create Menus
wp_create_nav_menu( 'Header Top Nav', array( 'slug' => 'header-menu' ) );
wp_create_nav_menu( 'Footer Bottom Nav', array( 'slug' => 'footer-menu' ) );
But missing is the ability to:
- Assign created menus to created theme locations
- Create menu items in created menus linking to created pages.
For the first request... Agus's suggestion is nice but fails to let me assign the menu of my choice to the location of my choice. The key here seems to be able to get a menu's ID from it's slug.
For the second missing link, the Docs say you can use wp_insert_post to add a 'nav_menu_item', but there are no instructions on how to actually accomplish this. Sure I can add a post to the database, but how to I link it's metadata to the correct post?