brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: wp menu builds a WordPress navigation menu from the terminal

WordPress
~/tips/tip-wordpress-menu-cli-build

wp menu create "Main menu"

Creates a classic menu, adds links and assigns it to a theme location by script.

Clicking a menu together is, I think, the slowest part of setting up a test site. WP-CLI can do it in four lines.

wp menu create "Main menu"
wp menu item add-post main-menu 2
wp menu item add-custom main-menu "Docs" https://example.com/docs/
wp menu location assign main-menu primary

The first line creates the menu, and its slug becomes main-menu. add-post adds an existing page or post by ID. add-custom adds any link with a title. The last line puts the menu in the theme’s primary location.

Location names differ per theme. wp menu location list shows the ones your theme registers. wp menu list shows all menus with their locations and item counts, and wp menu item list main-menu shows the items with their database IDs, which you need to move or delete one.

This works for classic themes. Block themes like Twenty Twenty-Five use the Navigation block instead, which stores its menu as a wp_navigation post. There, wp menu location list comes back empty and assigning a location has no visible effect.

Further reading: wp menu, wp menu item

More WordPress tips wp user application-password create anna backup-script --porcelain define( 'MEDIA_TRASH', true ); wp cli check-update wp theme delete --all wp media image-size All WordPress tips (85) All topics

Link