My theme has a custom menu assignment…
function my_register_my_menus() {
register_nav_menus(
array('header-menu' => __( 'Custom Header Menu' ) )
);
}
…and I’m creating an “installer” type plugin that, upon activation, I would like to hook into this custom menu and assign some pages to it as if they had been created manually.
However, the menu API is pretty new and to date, I’ve been unable to find any examples of how to do this.
I’m hoping someone here can give me some direction, examples or info on how to do it.
Thanks in advance 🙂
You can use
wp_nav_menu_{$menu->slug}_items
hook and add you link with a callback function, for example if your menu slug isheader-menu
then something like this:Update
I guess you would need to call wp_save_nav_menu_items which is the function used to save the menu items to the database.