wp menu

Списки, создание, назначение и удаление меню навигации активной темы.

See the Navigation Menus reference in the Theme Handbook.

Список команд Описание
wp menu create Создает новое меню.
wp menu delete Удаляет одно или несколько меню.
wp menu list Возвращает список меню.
wp menu item list Возвращает список элементов, связанных с меню.
wp menu item add-post Добавляет в меню указанную запись.
wp menu item add-term Добавляет в меню указанный термин (элемент таксономии).
wp menu item add-custom Добавляет произвольный пункт меню.
wp menu item update Обновляет указанный элемент меню.
wp menu item delete Удаляет один или несколько элементов из меню.
wp menu location list Отображает список зарегистрированных областей меню для текущей темы.
wp menu location assign Располагает указанное меню в указанную область меню.
wp menu location remove Удаляет указанное меню из указанной области меню.

Примеры

# Create a new menu
$ wp menu create "My Menu"
Success: Created menu 200.

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

# Create a new menu link item
$ wp menu item add-custom my-menu Apple http://apple.com --porcelain
1922

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

Исходный код команд


Создает новое меню.

Использование

wp menu create {menu-name} [--porcelain]

Можно указать Глобальные параметры и следующие:

{menu-name}
A descriptive name for the menu.
[--porcelain]
Output just the new menu id.

Примеры

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

Удаляет одно или несколько меню.

Использование

wp menu delete {menu}...

Можно указать Глобальные параметры и следующие:

{menu}...
The name, slug, or term ID for the menu(s).

Примеры

$ wp menu delete "My Menu"
Success: 1 menu deleted.

Возвращает список меню.

Использование

wp menu list [--fields={fields}] [--format={format}]

Можно указать Глобальные параметры и следующие:

[--fields={fields}]
Limit the output to specific object fields.
[--format={format}]

Render output in a particular format.
По умолчанию: table
Может быть:

  • table
  • csv
  • json
  • count
  • ids
  • yaml

Доступные поля

These fields will be displayed by default for each menu:

  • term_id
  • name
  • slug
  • count

These fields are optionally available:

  • term_group
  • term_taxonomy_id
  • taxonomy
  • description
  • parent
  • locations

Примеры

$ 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 {menu} [--fields={fields}] [--format={format}]

Можно указать Глобальные параметры и следующие:

{menu}
The name, slug, or term ID for the menu.
[--fields={fields}]
Limit the output to specific object fields.
[--format={format}]

Render output in a particular format.
По умолчанию: table
Может быть:

  • table
  • csv
  • json
  • count
  • ids
  • yaml

Доступные поля

These fields will be displayed by default for each menu item:

  • db_id
  • type
  • title
  • link
  • position

These fields are optionally available:

  • menu_item_parent
  • object_id
  • object
  • type
  • type_label
  • target
  • attr_title
  • description
  • classes
  • xfn

Примеры

$ 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 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]

Можно указать Глобальные параметры и следующие:

{menu}
The name, slug, or term ID for the menu.
{post-id}
Post ID to add to the menu.
[--title={title}]
Set a custom title for the menu item.
[--link={link}]
Set a custom url for the menu item.
[--description={description}]
Set a custom description for the menu item.
[--attr-title={attr-title}]
Set a custom title attribute for the menu item.
[--target={target}]
Set a custom link target for the menu item.
[--classes={classes}]
Set a custom link classes for the menu item.
[--position={position}]
Specify the position of this menu item.
[--parent-id={parent-id}]
Make this menu item a child of another menu item.
[--porcelain]
Output just the new menu item id.

Примеры

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

Добавляет в меню указанный термин (элемент таксономии).

Использование

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]

Можно указать Глобальные параметры и следующие:

{menu}
The name, slug, or term ID for the menu.
{taxonomy}
Taxonomy of the term to be added.
{term-id}
Term ID of the term to be added.
[--title={title}]
Set a custom title for the menu item.
[--link={link}]
Set a custom url for the menu item.
[--description={description}]
Set a custom description for the menu item.
[--attr-title={attr-title}]
Set a custom title attribute for the menu item.
[--target={target}]
Set a custom link target for the menu item.
[--classes={classes}]
Set a custom link classes for the menu item.
[--position={position}]
Specify the position of this menu item.
[--parent-id={parent-id}]
Make this menu item a child of another menu item.
[--porcelain]
Output just the new menu item id.

Примеры

$ wp menu item add-term sidebar-menu post_tag 24
Success: Menu item added.

Добавляет произвольный пункт меню.

Использование

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]

Можно указать Глобальные параметры и следующие:

{menu}
The name, slug, or term ID for the menu.
{title}
Title for the link.
{link}
Target URL for the link.
[--description={description}]
Set a custom description for the menu item.
[--attr-title={attr-title}]
Set a custom title attribute for the menu item.
[--target={target}]
Set a custom link target for the menu item.
[--classes={classes}]
Set a custom link classes for the menu item.
[--position={position}]
Specify the position of this menu item.
[--parent-id={parent-id}]
Make this menu item a child of another menu item.
[--porcelain]
Output just the new menu item id.

Примеры

$ wp menu item add-custom sidebar-menu Apple http://apple.com
Success: Menu item added.

Обновляет указанный элемент меню.

Использование

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}]

Можно указать Глобальные параметры и следующие:

{db-id}
Database ID for the menu item.
[--title={title}]
Set a custom title for the menu item.
[--link={link}]
Set a custom url for the menu item.
[--description={description}]
Set a custom description for the menu item.
[--attr-title={attr-title}]
Set a custom title attribute for the menu item.
[--target={target}]
Set a custom link target for the menu item.
[--classes={classes}]
Set a custom link classes for the menu item.
[--position={position}]
Specify the position of this menu item.
[--parent-id={parent-id}]
Make this menu item a child of another menu item.

Примеры

$ wp menu item update 45 --title=WordPress --link='http://wordpress.org' --target=_blank --position=2
Success: Menu item updated.

Удаляет один или несколько элементов из меню.

Использование

wp menu item delete {db-id}...

Можно указать Глобальные параметры и следующие:

{db-id}...
Database ID for the menu item(s).

Примеры

$ wp menu item delete 45
Success: 1 menu item deleted.

Отображает список зарегистрированных областей меню для текущей темы.

Использование

wp menu location list [--format={format}]

Можно указать Глобальные параметры и следующие:

[--format={format}]

Render output in a particular format.
По умолчанию: table
Может быть:

  • table
  • csv
  • json
  • count
  • yaml
  • ids

Доступные поля

These fields will be displayed by default for each location:

  • name
  • description

Примеры

$ wp menu location list
+----------+-------------------+
| location | description       |
+----------+-------------------+
| primary  | Primary Menu      |
| social   | Social Links Menu |
+----------+-------------------+

Располагает указанное меню в указанную область меню.

Использование

wp menu location assign {menu} {location}

Можно указать Глобальные параметры и следующие:

{menu}
The name, slug, or term ID for the menu.
{location}
Location's slug.

Примеры

$ wp menu location assign primary-menu primary
Success: Assigned location primary to menu primary-menu.

Удаляет указанное меню из указанной области меню.

Использование

wp menu location remove {menu} {location}

Можно указать Глобальные параметры и следующие:

{menu}
The name, slug, or term ID for the menu.
{location}
Location's slug.

Примеры

$ wp menu location remove primary-menu primary
Success: Removed location from menu.