In This Tutorial:
Knowing certain details about your menu(s) is important for managing them via the command line. For instance, if you want to display a particular menu on your website, you must know the available locations to include in the syntax of the command. However, thanks to the available sub-command list, we can gather the details we need, without having to leave the command line. In this guide, you will learn the steps to find important details about your menu(s) to manage them using WP-CLI.
List Existing Menus
The menus you have created can be listed using the wp menu list command. Follow the steps below to list your menus and obtain the additional information needed to manage them.
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 list
The output will be similar to the example below:
[email protected] [~/public_html/wp]# wp menu list +---------+------------------+------------------+-----------+-------+ | term_id | name | slug | locations | count | +---------+------------------+------------------+-----------+-------+ | 8 | Primary New Menu | primary-new-menu | | 0 | | 4 | primary-nav | primary-nav | top | 0 | | 7 | primary-new | primary-new | | 0 | | 5 | social-media | social-media | social | 0 | +---------+------------------+------------------+-----------+-------+
Notice that the output is formatted nicely displaying the details of the existing menus. For instance, the menu named: primary-nav is assigned to the location: top. This means that the primary-nav menu will be displayed where the top menu is located according to the active theme.
List Available Menu Locations
In order to display a menu on your website you assign the menu a location. Since you must first know the location(s) available to specify in the command, you need to find the location details. The instructions below will guide you through the process of identifying the available menu locations (for the theme that is currently activated), 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.Run the following command:
wp menu location list
The output below, provides an example that lists the available menu locations for your enabled theme.
[email protected] [~/public_html/wp]# wp menu location list +----------+-------------------+ | location | description | +----------+-------------------+ | top | Top Menu | | social | Social Links Menu | +----------+-------------------+
Here, you can see the two (2) available locations, top and social.
List Menu Items
You can review the items included in a particular menu by using the wp menu item list sub-command. Follow the steps below to find the items included in a 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.Run the following command:
wp menu item list primary-nav
NOTE: Be sure to replace primary-nav with the actual name of the menu you would like to list items for.The output below provides an example of the menu items and details listed:
[email protected] [~/public_html/wp]# wp menu item list primary-nav +-------+-----------+--------------+---------------------------------+----------+ | db_id | type | title | link | position | +-------+-----------+--------------+---------------------------------+----------+ | 38 | post_type | Home | https://w...com/wp/ | 1 | | 43 | post_type | About Us | https://w...com/wp/about-us/ | 2 | | 45 | post_type | Clients | https://w...com/wp/clients/ | 3 | | 47 | post_type | Gallery | https://w...com/wp/gallery/ | 4 | | 49 | post_type | Resume | https://w...com/wp/resume/ | 5 | | 51 | post_type | Info | https://w...com/wp/info/ | 6 | | 53 | post_type | Testimonials | https://w...com/wp/testimonials/ | 7 | | 55 | post_type | Contact Us | https://w...com/wp/contact-us/ | 8 | | 23 | taxonomy | Blog | https://w...com/wp/./blog/ | 9 | +-------+-----------+--------------+---------------------------------+----------+
Now that you are familiar with how to find the details for your menu(s), you can utilize WP-CLI to manage your menu(s) from the command line.
Learn more about WP-CLI, the command-line interface for WordPress, and how to streamline your WordPress maintenance workflows!