this is the general gist of what you need to do, you’ll want to add some checks in here, make sure you get a valid menu returned, etc..
$locations = get_theme_mod( 'nav_menu_locations' );
$menu = wp_get_nav_menu_object( reset( $locations ) ); // get first item in menu locations array
$menu_item_data = array(
'menu-item-object-id' => $your_page->ID, // ID of the page you want to add
'menu-item-parent-id' => 0, // top level menu item
'menu-item-position' => 0, // setting position to 0 will add it to the end
'menu-item-object' => 'page',
'menu-item-type' => 'post_type',
'menu-item-status' => 'publish'
);
wp_update_nav_menu_item( $menu->term_id, 0, $menu_item_data );
Related Posts:
- What’s the easiest way to duplicate an entire navigation menu?
- Popup Maker nav menu item not working
- Set the active Navigation Menu from a plugin
- Easiest way to add dropdown to a page
- How can I add a fixed vertical menu to my site? [closed]
- WordPress site hamburger menu toggle not working
- WP Super Large Menu Problem
- How to build a navigation menu for long-form texts like this one
- How can I create a navigation menu in the sidebar that can also act like a slider?
- Prevent primary navigational menu from expanding during page load (WordPress / Astra Theme)
- Add section (add_settings_section) to a custom page (add_submenu_page)
- How to call “page specific menu items” in template [closed]
- Custom wp_nav_menu output (displaying all child elements of top menu element in current branch)
- wp_nav_menu(); Outside WordPress installation
- Does the ‘nav_menu_css_class’ filter accept 2 or 3 arguments?
- How do I make a wordpress plugin with menu item etc
- Creating WordPress Plugin solely for Admin panel with dash menu and submenus
- Creating a menu page in a Object Oriented developed plugin
- Include Max mega menu Plugin into theme
- How use %like% in sql statement wordpress
- Wondering what these multi-colored extra pages are?
- Menus, but not by theme location
- How to make a customize role and view a specific plugins base on that role?
- Creating a nav menu
- looking for navigation plugin (accordion) [closed]
- How to get the element ID from new menu list that added with add_filter()?
- Merging Two menus in the backend into one menu
- Polylang : Interverting languages after development [closed]
- Delete mobile menu button [closed]
- html generated by theme exist but doesnt appear in browser
- Changing page URL and connect newsletter to MailChip
- Dynamic admin submenu
- Center and hide overflow of WP toolbar custom links
- How to remove admin main menu name repetition
- Custom Permalink Plugin and Current Page/Ancestor in Menus
- wp-custom-menu filter removes the current_page_item class
- add_action does not call the function
- How to use my menu PHP code as sidebar?
- Redirect to another page using contact form 7? [closed]
- Creating Featured Content Boxes
- Hide a Menu Item on Login
- How to get menu location in wp_update_nav_menu hook
- PHP script from functions php is loaded via admin-ajax to div…and the result is 0, not the desired content
- Ambrosite Next/Previous Post Link Plus or WP next_post_link to cycle through top level category
- Progmatically adding menu links to the default (Top) or Footer menu
- $pages = get_pages(‘child_of=’.$post->ID); Why arguments are concatenated?
- Changing location of “About me” section
- Need to revert to an older version of wordpress
- WordPress Custom Menu Admin helper plugin
- 2 wordpress site same database
- Hook on creating a menu entry?
- Dropdown menu on click change
- navigation among single posts
- Adding a pagenavi to function for displaying bookmarks
- Button and Countdown overlapping mobile menu
- Navbar affect loading all products
- Slideout submenu in mobile
- Display posts by alphabetical order
- Mobile Menu and Mobile Sidebar missing
- WP Forms not displaying,becomming an fatal error
- WordPress Dashboard add user password not working, etc
- Add custom WordPress admin page with pretty url via code
- I need to show side menu in wordpress
- Scroll to ID broken in main menu
- Create survey that redirects to sidebar menu customized to answers
- Pagination (including title of each page) in a post for a long posts
- Circular Menu to show on pages
- Warning: sprintf(): Too few arguments in nav-menu-template.php
- jquery plugin won’t fire when hamburger class element clicked
- Page Contents showing in Footer Area
- How to disable users to view Other pages
- Sub Categories in drop down menu
- Admin page and admin menu. Permissions plugin
- Power Menus plugin destroys menu after adding new item
- How to assign plugin to top level menu?
- Adding icons next to categories in wp_nav_menu
- Creating a page that does not show up in the frontend navigation bar
- add_media_page function not creating submenu
- How can I pass value to function in add_menu_page?
- Automatically add child pages to menu
- Drop down menu location select widget
- How to add plugin activity in the menus?
- How change menu for each user in plugin?
- Menu items’ links are not working properly and added images
- how to change/remove/hide menu under installed plugins
- Category archive in menu
- Redirect url in plugin to somewhere else?
- How to activate/deactivate menu tab and keep the same id?
- How can I add different menus (different style menu) on each page?
- Make a Custom template for a specific category in wordpress
- Call to a member function get_page_permastruct() on null
- Automatically put a menu on every post
- How to validate password length in wordpress
- Why plugin’s icon for the menu not found?
- Plugin: Custom menu item problem
- Is it possible to know which menus are owned by a plugin?
- How to make horizontal scrolling menu [closed]
- My wp_update_nav_menu action is firing twice
- How does one add numbers to an admin menu?
- Adding fontAwesome to Primary Menu returns after saving the menu