Create a navigation menu with three links
Description: Create a menu named Top Menu with three items: Home (the home page address), About (a page of your site) and Docs (the link https://wordpress.org/documentation/). List the items.
Hint:
wp menu create,wp menu item add-postandwp menu item add-custom.
Solution
$ wp post create –post_type=page –post_title="About" –post_status=publish –porcelain
5
$ wp menu create "Top Menu"
Success: Created menu 2.
$ wp menu item add-custom top-menu "Home" http://example.com/
Success: Menu item added.
$ wp menu item add-post top-menu 5 –title="About"
Success: Menu item added.
$ wp menu item add-custom top-menu "Docs" https://wordpress.org/documentation/
Success: Menu item added.
$ wp menu item list top-menu –fields=db_id,title,type,link
db_id title type link
6 Home custom http://example.com/
7 About post_type http://example.com/about/
8 Docs custom https://wordpress.org/documentation/
How it works
- A menu is a term of the taxonomy
nav_menu. Each link is a post of the typenav_menu_item. - A custom item keeps any URL, while
add-postlinks to a page or post by ID and keeps the link updated.
Read WordPress Menus.
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |