How to Create and Delete Menus Using WP-CLI

WordPress Hosting by InMotion Hosting includes WordPress Command Line Interface (WP-CLI). This convenient tool allows you to work on your WordPress website(s) directly from the command line. Once you are familiar with the syntax and available commands, you will be able to quickly modify common elements of your website(s), like menus.

Menus are essential for providing a focal point for your visitors to locate important information contained within your website. In this guide, you will learn how to create and delete a menu with WP-CLI, using the command wp menu.

Create a New Menu

Creating a new menu is simple using the sub-command wp menu create. The steps below will guide you through the process of creating a new menu from the command line, using WP-CLI.

  1. SSH into your server as the cPanel user that owns the website you would like to work with.

  2. Use the cd command to switch to the document root directory of your website.

    Example: cd public_html/wp

  3. Run the following command:

    wp menu create primary-nav

  4. The output will be similar to the example below:

    [email protected] [~/public_html/wp]# wp menu create primary-nav Success: Created menu 3.

Delete a Menu

If you are unsatisfied with a menu you have created, you can remove it by using the wp menu delete sub-command. The following steps will guide you through the process of deleting a menu via the command line, using WP-CLI.

  1. SSH into your server as the cPanel user that owns the website you would like to work with.

  2. Use the cd command to switch to the document root directory of your website.

    Example: cd public_html/wp

  3. Run the following command:

    wp menu delete primary-nav

  4. The output will be similar to the following example:

    [email protected] [~/public_html/wp]# wp menu delete primary-nav Success: Menu(s) deleted.

Congratulations! Now, you know how to create and delete menus from your WordPress website via the command line using WP-CLI.

Learn more about WP-CLI, the command-line interface for WordPress, and how to streamline your WordPress maintenance workflows!

JB
John-Paul Briones Content Writer II

John-Paul is an Electronics Engineer that spent most of his career in IT. He has been a Technical Writer for InMotion since 2013.

More Articles by John-Paul

Was this article helpful? Join the conversation!