wp menu

Lists, creates, assigns, and deletes the active theme’s navigation menus.

See the Navigation Menus reference in the Theme Handbook.

Subcommands

Command Description
wp menu create Creates a new menu.
wp menu delete Deletes one or more menus.
wp menu item List, add, and delete items associated with a menu.
wp menu list Gets a list of menus.
wp menu location Assigns, removes, and lists a menu’s locations.

wp menu create

Creates a new menu.

Synopsis

wp menu create <menu-name> [--porcelain]

Options

<menu-name>
: A descriptive name for the menu.

[--porcelain]
: Output just the new menu id.

Examples

$ wp menu create "My Menu"
Success: Created menu 200.

wp menu delete

Deletes one or more menus.

Synopsis

wp menu delete <menu>...

Options

<menu>...
: The name, slug, or term ID for the menu(s).

Examples

$ wp menu delete "My Menu"
Deleted menu 'My Menu'.
Success: Deleted 1 of 1 menus.

wp menu list

Gets a list of menus.

Synopsis

wp menu list [--fields=<fields>] [--format=<format>]

Options

[--fields=<fields>]
: Limit the output to specific object fields.

[--format=<format>]
: Render output in a particular format.

  • default: table
  • options: table, csv, json, count, ids, yaml

Available Fields

Default fields: term_id, name, slug, count

Optional fields: term_group, term_taxonomy_id, taxonomy, description, parent, locations

Examples

$ wp menu list
+---------+----------+----------+-----------+-------+
| term_id | name     | slug     | locations | count |
+---------+----------+----------+-----------+-------+
| 200     | My Menu  | my-menu  |           | 0     |
| 177     | Top Menu | top-menu | primary   | 7     |
+---------+----------+----------+-----------+-------+

wp menu item

List, add, and delete items associated with a menu.

Subcommands

Command Description
wp menu item add-custom Adds a custom menu item.
wp menu item add-post Adds a post as a menu item.
wp menu item add-term Adds a taxonomy term as a menu item.
wp menu item delete Deletes one or more items from a menu.
wp menu item list Gets a list of items associated with a menu.
wp menu item update Updates a menu item.

wp menu item add-custom

wp menu item add-custom <menu> <title> <link> [--description=<description>] [--attr-title=<attr-title>] [--target=<target>] [--classes=<classes>] [--position=<position>] [--parent-id=<parent-id>] [--porcelain]

wp menu item add-post

wp menu item add-post <menu> <post-id> [--title=<title>] [--link=<link>] [--description=<description>] [--attr-title=<attr-title>] [--target=<target>] [--classes=<classes>] [--position=<position>] [--parent-id=<parent-id>] [--porcelain]

wp menu item add-term

wp menu item add-term <menu> <taxonomy> <term-id> [--title=<title>] [--link=<link>] [--description=<description>] [--attr-title=<attr-title>] [--target=<target>] [--classes=<classes>] [--position=<position>] [--parent-id=<parent-id>] [--porcelain]

wp menu item delete

wp menu item delete <db-id>...

wp menu item list

wp menu item list <menu> [--fields=<fields>] [--format=<format>]

wp menu item update

wp menu item update <db-id> [--title=<title>] [--link=<link>] [--description=<description>] [--attr-title=<attr-title>] [--target=<target>] [--classes=<classes>] [--position=<position>] [--parent-id=<parent-id>]

Examples

# Add an existing post to an existing menu
$ wp menu item add-post sidebar-menu 33 --title="Custom Test Post"
Success: Menu item added.

# Create a new menu link item
$ wp menu item add-custom sidebar-menu Apple http://apple.com
Success: Menu item added.

# Delete menu item
$ wp menu item delete 45
Success: Deleted 1 of 1 menu items.

# List menu items
$ wp menu item list main-menu
+-------+-----------+-------------+---------------------------------+----------+
| db_id | type      | title       | link                            | position |
+-------+-----------+-------------+---------------------------------+----------+
| 5     | custom    | Home        | http://example.com              | 1        |
| 6     | post_type | Sample Page | http://example.com/sample-page/ | 2        |
+-------+-----------+-------------+---------------------------------+----------+

wp menu location

Assigns, removes, and lists a menu’s locations.

Subcommands

Command Description
wp menu location assign Assigns a location to a menu.
wp menu location list Lists locations for the current theme.
wp menu location remove Removes a location from a menu.

wp menu location assign

wp menu location assign <menu> <location>

wp menu location list

wp menu location list [--format=<format>]

wp menu location remove

wp menu location remove <menu> <location>

Examples

# List available menu locations
$ wp menu location list
+----------+-------------------+
| location | description       |
+----------+-------------------+
| primary  | Primary Menu      |
| social   | Social Links Menu |
+----------+-------------------+

# Assign the 'primary-menu' menu to the 'primary' location
$ wp menu location assign primary-menu primary
Success: Assigned location primary to menu primary-menu.

# Remove the 'primary-menu' menu from the 'primary' location
$ wp menu location remove primary-menu primary
Success: Removed location from menu.