How to Add and Delete Menu Items Using WP-CLI Updated on November 19, 2021 by InMotion Hosting Contributor 2 Minutes, 34 Seconds to Read In This Tutorial: Add Menu Item Delete Menu Item WordPress Hosting plans offered by InMotion Hosting feature WP-CLI. This means that you can manipulate various aspects of your WordPress website, directly from the command line. In this guide, you will learn how to use the wp menu command to add and delete menu items, using WP-CLI. Create Menu Item If you would like to add an item to your menu, you can use the wp menu item sub-command. The following steps will guide you through the process of adding a custom URL, a Post, and a Page to your menu, using WP-CLI. SSH into your server as the cPanel user that owns the website you would like to work with. Use the cd command to switch to the document root directory of your website. Example: cd public_html/wp NOTE: Be sure to replace public_html/wp with the actual path to the document root directory of your website. Click on the button below for the menu item you would like to add, to expand and display the command used for each one. Post Run the following command: wp menu item add-post primary-nav 39 NOTE: Be sure to replace primary-nav with the actual name of the menu and 39 with the actual post_id of the post you would like to add to your menu. The output will be similar to the example below: [email protected] [~/public_html/wp]# wp menu item add-post primary-nav 39 Success: Menu item added. Page Run the following command: wp menu item add-post primary-nav 42 NOTE: Be sure to replace primary-nav with the actual name of the menu and 42 with the actual ID of the Page you would like to add to your menu. The output will be similar to the example below: [email protected] [~/public_html/wp]# wp menu item add-post primary-nav 42 Success: Menu item added. Custom URL Run the following command: wp menu item add-custom primary-nav “My Custom Link” https://www.example.com NOTE: Be sure to replace primary-nav with the actual name of the menu, “My Custom Link” with the actual title (enclosed in quotes if there are blank spaces in the title) and https://www.example.com with the actual URL you would like to add to your menu. The output will be similar to the example below: [email protected] [~/public_html/wp]# wp menu item add-custom primary-nav "My Custom Link" https://www.example.com Success: Menu item added. Remove Menu Item SSH into your server as the cPanel user that owns the website you would like to work with. Use the cd command to switch to the document root directory of your website. Example: cd public_html/wp NOTE: Be sure to replace public_html/wp with the actual path to the document root directory of your website. Run the following command: wp menu item delete 120 NOTE: Be sure to replace 120 with the actual db_id of the menu item you would like to delete from your menu. [email protected] [~/public_html/wp]# wp menu item delete 120 Success: Menu item(s) deleted. Learn more about WP-CLI, the command-line interface for WordPress, and how to streamline your WordPress maintenance workflows! Share this Article IC InMotion Hosting Contributor Content Writer InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals! More Articles by InMotion Hosting Related Articles Install and Configure WP-CLI How to Create and Delete a WordPress Page Using WP-CLI Install a Theme Using WP-CLI Install WordPress Using WP-CLI Manage WordPress Comments Using WP-CLI Update WordPress Using WP-CLI Manage WordPress Users Using WP-CLI WP-CLI search-replace Command Delete WordPress Transients Using WP-CLI Manage WordPress Plugins with WP-CLI