I guess it doesn’t need anymore explanation:
$mymenu = wp_get_nav_menu_object('Main Navigation Menu');
$menuID = (int) $mymenu->term_id;
$myPage = get_page_by_title('About Us');
$itemData = array(
'menu-item-object-id' => $myPage->ID,
'menu-item-parent-id' => 0,
'menu-item-position' => 2,
'menu-item-object' => 'page',
'menu-item-type' => 'post_type',
'menu-item-status' => 'publish'
);
wp_update_nav_menu_item($menuID, 0, $itemData);
Related Posts:
- add_menu_page() with different name for first submenu item
- How to add sub-menu to a menu generated by wp_nav_menu by using plugin
- Change the_title() of a page dynamically
- How do I programatically insert a new menu item?
- Add Dividers or Separators Between Nav Menu Items
- Nav Menu meta failing to import
- Overwriting Core WordPress Functions with Plugins
- Some nav-menu filters do nothing
- Determine which theme location a wp_get_nav_menu_items is for
- Can I add pages to my custom menu via script?
- Replacing WordPress menu functionality with a plugin
- Hook event for upload image in the menu
- Why isn’t the Settings API designed to work for plugins using custom admin menus? [duplicate]
- How do I approach removing menu items on the fly based on settings in my plugin?
- What is the difference between current_page_parent and current_page_ancestor?
- Delete a specific item menu when I deactivate my plugin
- Create a Page via plugin
- Add Submenu Link in add_submenu_page That Opens in a New Window
- How to assign a WP 3.0 custom nav menu to a theme’s navigation menu location via script?
- Header Button Chance Polylang Elementor
- PHP 7 – Class Method Compatibility Issue
- How do I add a custom sublevel menu specified in one directory to a custom top level menu specified in another directory?
- Add notification bubble notice in navigation using transients
- Get Current Menu Location inside Nav_Walker
- Adding custom fields to WordPress nav menus
- Sub Menu content is being duplicated
- Plugin menu addition in multisite
- Remove unwanted elements for a wp_nav_menu
- Is this best practice for Dynamically adding items to WordPress menus?
- How to remove or add submenu item on plugin activate or deactive
- Custom code for WordPress dynamic menu
- How do I access the menus produced by Dashboard > Appearance > Menus
- wordpress add_submenu_page adds broken link
- WP Enqueue style on all plug-in pages
- Add child pages to submenu automatically
- Customize existing menu item
- Menu page with minimum capability as ‘Subscriber’ doesn’t allow ‘Admin’ to access it?
- Issue with plugin sub menu and pages
- How to add Plugin functionality in WordPress Frontend Menus
- How to hide page links from theme menu
- WP_NAV_MENU filter targets all menus
- How do I add a menu item to a Pods admin menu?
- Add user managable titles to custom menus?
- How to create archive page to add in menu
- How to show only the last two categories in a menu?
- Always hide a page from the menu
- remove different admin menu for specific users
- How to get an array out of a nav menu if it’s a plugin?
- What happens when you create/edit a menu
- Plugin admin list pages as submenu
- Adding parent custom post type menu option
- Create and style menu
- Change the class of wordpress menu
- Invalid Menu Items
- Declaration of mandoe_menu_walker::start_el(&$output, $item, $depth, $args) must be compatible with Walker::start_el(…)
- Custom Nav Walker $item->url producing malformed hyperlinks
- Displaying an Uploaded Image as a Custom Avatar in WordPress
- Adding a navigation with wp_nav_menu() to a custom block in the site editor
- the_content after all shortcodes are parsed
- How do I resolve Notice: Undefined offset: 0 in /wp-includes/capabilities.php on line 1145
- Category listing with thumbnail and description on home page
- URLs of plugin resources?
- anything like add_meta_box for categories?
- WordPress: After Gutenberg plugin migration to block.json the localization/ translations with PolyGlot in JavaScript does not work anymore
- What is the Difference between directly call a function and call a function using add_action?
- What is better way to use Bootstrap inside admin panel?
- Updating my plugin without releasing a new version
- Is it possible to check is loaded language files correctly with WordPress plugin?
- Where to store the name of a custom table?
- Upgrade private plugin without deleting files?
- Saving value of a selection option in comment form as comment meta
- Is there some way to provide the user a list of existing content in a CPT
- Issue with querying
- There is a problem in the gutenberg block I developed. Problem is with withInstanceId
- best way to make a WordPresss multisite that is secure but at the same time supporting my plugin development efforts
- How to change title tag at page after loaded post?
- How to get post content by get_posts function?
- Getting following web services error after activating the Rewards Plugin
- WordPress custom taxonomy check box to dropdown
- How to remove plugin-specific custom taxonomy terms when plugin is uninstalled?
- How to modify files inside wp-includes directory in wordpress
- Fatal error: Call to a member function get_page_permastruct() on a non-object
- How to apply style_loader_src filter with exclusion of a specific file?
- Which is the better way to store images for the plugin?
- Minimum Widget Width for Plugin Development
- Should I use wp-content/cache or [PLUGIN_DIR]/cache?
- Restrict certain actions to plugin-specific admin menu pages only
- how to add custom fields into new & update post page?
- List all user post API endpoint
- Condition to check previous next article post title
- How to display plugin with javascript using markup of the theme?
- Multisite and the JSON REST API: How to?
- Looping single post in a theme
- WP Ajax on page load not working on bluehost but was working on Godaddy
- How can I send an id over the url?
- Creating custom Insert Media page
- Get fields of a widget
- How do you filter get_media_items by mime type in a custom media upload tab?
- Trying to build a plugin – Cannot modify header information
- Is it smart to require_once wp-admin/includes/plugin.php when you need only one function from it