Reputation: 1257
I want to add my own menu/links to the primary and secondary menu.
What filter/action should I watch for and how do I add my own menu so it can fit any, (or most) templates.
Upvotes: 0
Views: 66
Reputation:
If you wanted to create a menu programmatically, you could do something like:
$menu_id = wp_create_nav_menu($menu_name);
// Add items
wp_update_nav_menu_item($menu_id, 0, array(
'menu-item-title' => // Menu text,
'menu-item-classes' => // Item classes,
'menu-item-url' => // URL to link to,
'menu-item-status' => 'publish'));
...
If you want to add menu items to an existing menu you can use the wp_get_nav_menu_items filter:
function add_menu_items( $items, $menu, $args ) {
// Create menu items and add to $items array
return $items;
}
add_filter( 'wp_get_nav_menu_items', 'add_menu_items', 10, 3 );
Upvotes: 1