Try this link may helpful
http://codex.wordpress.org/Function_Reference/wp_create_nav_menu
// Check if the menu exists
$menu_exists = wp_get_nav_menu_object( $menu_name );
// If it doesn't exist, let's create it.
if( !$menu_exists){
$menu_id = wp_create_nav_menu($menu_name);
// Set up default menu items
wp_update_nav_menu_item($menu_id, 0, array(
'menu-item-title' => __('Home'),
'menu-item-classes' => 'home',
'menu-item-url' => home_url( "https://wordpress.stackexchange.com/" ),
'menu-item-status' => 'publish'));
wp_update_nav_menu_item($menu_id, 0, array(
'menu-item-title' => __('Custom Page'),
'menu-item-url' => home_url( '/custom/' ),
'menu-item-status' => 'publish'));
}
Hope it may help 🙂
Related Posts:
- Customizing Only a Specific Menu using the “wp_nav_menu_items” Hook?
- How make top level menu item not have link, but have sub-menus that are linked?
- Using a menu walker add a custom item at the end of the menu’s items
- Add settings to menu items in the Customizer
- Generate a Menu that Displays Child Pages using wp_list_pages() with the New Menu Functionality in WordPress 3.0?
- How Does The Walker Class Work?
- WordPress Shortcode in Menu Item Title
- Calling the Menu Title within wp_nav_menu array function
- How to hide an item from a menu to logged out users (without a plugin)
- Menu items (all menus) being deleted randomly on their own [duplicate]
- Large WP 3.0 menu times out and won’t save
- How to apply a class to the second word in menu list item?
- Put a wp_nav_menu inside another one
- How to switch between the Primary Menus programmatically?
- if role is logged in then do something
- WordPress wp_nav_menu within iFrame
- Generate a Menu that displays all child pages of top level parent
- Terms with more than one occurrence have current-menu-item class in menu
- Nav menu items disappearing (but not immediately)
- Check if wp_nav_menu items have submenus
- start_lvl on Walker is not working
- How to get Menu Navigation Labels to output HTML
- custom menu not found
- wp_nav_menu doesn’t generate parent/ancestor classes
- How to add text before WordPress menu item href
- WP_nav_menu fallback not working
- How to conditionally register nav menus with advanced custom fields?
- Pending Custom Link in Menu
- Benefits of using Nav Walker?
- Change where navigation bar links?
- Social Links Menu displays icon instead of text (twentyfifteen) [closed]
- has_children in custom nav_walker
- I’m having a lot of trouble since upgrade to 3.0.1 with get_page_children() function
- How to add #navbar to all page links?
- How to add wechat (weixin) link to navigation menu?
- Create search form in menu as in Twenty Fourteen theme
- Add link at the end of wp_nav_menu
- Link that refers to a menu item with dynamically generated URL
- Custom walker nav – Add sequential number as class
- Side Menu Icon Expandable
- delete all post with certain meta_keys
- Make nav-menus.php available for editor
- how to add custom wp_nav_menu class css selector to ul and a tags?
- Need Random Category Nav Menu
- Split into two seperate unordered lists with custom walker
- Can’t add a setting to the “nav_menus” customizer panel
- replace existing menu programtically
- Submenu page buttons are blank
- Main menu gets replaced when second menu is created
- Hide menu items if the page content is empty
- Theme only supports one menu? [closed]
- Problem adding ‘has-children’ class to wp_nav_menu
- exclude pages in custom menu
- Adding new pages to Menu
- set certain item in nav walker to active when on archive pages or singles
- wp_nav_menu() | Outputting my own custom code using built in features
- How to reference argument data for wp_nav_menu() from functions.php
- Creating menu always gives error A name is required for this term
- Showing the same menu in multiple location
- Creating custom menu with custom themes
- Expected snippet value not showing
- Wp Nav Menu div containers
- wp_nav_menu with WP as pure CMS
- Simple form to add custom links to menu?
- What’s the best way to customize the WordPress Menu Page (in admin)
- Add posts from a category to menu with all posts in it as sub menu
- Possible to append class to nav menu added to widget area?
- Page dependent sub-menu?
- Making the menu toggled open on mobile devices Illustratr theme
- How to include second layer sub menu to Walker Nav?
- need help in wordpress navbar setup
- How can I creat custom menu with bootstrap
- Error: Declaration of MyClass::start_lvl() should be compatible with that of Walker_Nav_Menu::start_lvl()
- Restrict user to edit only edit a certain menu
- Where is the source code in the console coming from?
- Migrate old blogroll to menus automatically
- Getting parent object_id of child menu items in WordPress menu
- How to remove a sub-menu using walker hooks/filters without relying on a custom walker?
- display cart information within li of cart menu item
- Calling wordpress menu outside ignores custom menu item
- Specific Page that convert Hyperlink to anchor in nav menu
- change link of menu particular tab
- Next page link via the custom menu
- How can I make this custom design menu work in wordpress?
- Active menu item / category
- Add different span class to wp nav menu
- Menu not always using correct link
- Custom Menus and taxonomies
- Help with changing style of the extended menu drop down [closed]
- How we show pages in dropdown
- Menu support for touch devices
- wp_nav_menu doesn’t show on index page
- Automatically add new posts to a specific menu name
- can anyone help me converting my static menu to wp_nav_menu I’am trying to add static menu item to WordPress Menu
- Elegant way of adding an CTA to a menu
- Theme supports only one menu. I need to add more – but how? [closed]
- How to set menu Display location
- How to add custom menu to block theme?
- get menu name for the current displayed page
- Database structure Menu Item