Wp menu (WP-CLI)
Versie door Jeroen Strompf (overleg | bijdragen) op 16 jun 2022 om 19:35 (Nieuwe pagina aangemaakt met '''wp menu''" Werk met menu's en menu-items. Deze laatste gaan via het subcommando <code>wp menu item</code> <pre> $ wp help menu NAME wp menu DESCRIPTION L...')
wp menu" Werk met menu's en menu-items. Deze laatste gaan via het subcommando wp menu item
$ wp help menu NAME wp menu DESCRIPTION Lists, creates, assigns, and deletes the active theme's navigation menus. SYNOPSIS wp menu <command> SUBCOMMANDS create Creates a new menu. delete Deletes one or more menus. item List, add, and delete items associated with a menu. list Gets a list of menus. location Assigns, removes, and lists a menu's locations. See the [Navigation Menus][1] reference in the Theme Handbook. --- [1] https://developer.wordpress.org/themes/functionality/navigation-menus/ EXAMPLES # 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 help menu item NAME wp menu item DESCRIPTION List, add, and delete items associated with a menu. SYNOPSIS wp menu item <command> SUBCOMMANDS add-custom Adds a custom menu item. add-post Adds a post as a menu item. add-term Adds a taxonomy term as a menu item. delete Deletes one or more items from a menu. list Gets a list of items associated with a menu. update Updates a menu item. 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: 1 menu item deleted.
$ wp help menu item list NAME wp menu item list DESCRIPTION Gets a list of items associated with a menu. SYNOPSIS wp menu item list <menu> [--fields=<fields>] [--format=<format>] OPTIONS <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. --- default: table options: - table - csv - json - count - ids - yaml --- AVAILABLE FIELDS 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 EXAMPLES $ 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 | +-------+-----------+-------------+---------------------------------+----------+
Voorbeeld
$ wp menu item list main-menu +-------+-----------+-----------------------------------------+-------------------------------------------+----------+ | db_id | type | title | link | position | +-------+-----------+-----------------------------------------+-------------------------------------------+----------+ | 60057 | post_type | Widgets op Merk | http://en.s1/alle-merken/ | 1 | | 52263 | post_type | ABL | http://en.s1/widgets12345-voor-aeg-kies-j | 2 | | | | | e-apparaat/ | | | 52264 | post_type | Black & Blacker | http://en.s1/widgets12345-voor-black-deck | 3 | | | | | er-kies-je-apparaat/ | | | 61499 | custom | Bros | http://en.s1/widgets12345-voor-bosch-kies | 4 | | | | | -je-apparaat/ | | | 52266 | post_type | DeWil | http://en.s1/widgets12345-voor-de-walt-ki | 5 | | | | | es-je-apparaat/ | | | 52267 | post_type | Fenn | http://en.s1/widgets12345-voor-fein-kies- | 6 | +-------+-----------+-----------------------------------------+-------------------------------------------+----------+
$ wp help menu item update NAME wp menu item update DESCRIPTION Updates a menu item. SYNOPSIS 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>] OPTIONS <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. EXAMPLES $ wp menu item update 45 --title=WordPress --link='http://wordpress.org' --target=_blank --position=2 Success: Menu item updated.
Verkrijg een lijst van menu's in het actieve thema. Die lijst heb je nodig als je menu-items wilt bewerken, omdat je dan de slug, naam of ID van het bijbehorende menu moet geven. De lijst van menu's is doorgaans nogal statisch en voorspelbaar - Zie het voorbeeld onderaan dit hoofdstuk:
$ wp help menu list NAME wp menu list DESCRIPTION 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 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 EXAMPLES $ wp menu list +---------+----------+----------+-----------+-------+ | term_id | name | slug | locations | count | +---------+----------+----------+-----------+-------+ | 200 | My Menu | my-menu | | 0 | | 177 | Top Menu | top-menu | primary | 7 | +---------+----------+----------+-----------+-------+
Voorbeeld
$ wp menu list +---------+-------------------------+-------------------------+----------------------+-------+ | term_id | name | slug | locations | count | +---------+-------------------------+-------------------------+----------------------+-------+ | 17 | Main menu | main-menu | primary | 38 | | 1646 | Mobile Bottom Menu | mobile-bottom-menu | mobile-bottom,footer | 5 | | 1645 | Mobile Top Menu | mobile-top-menu | mobile-top | 12 | | 22 | Product categories menu | product-categories-menu | product_categories | 1 | | 44753 | Utility menu | utility-menu | utility | 1 | +---------+-------------------------+-------------------------+----------------------+-------+