Roots Discourse

How to handle deployments of menus in WP

#1

Hi

I am relatively new to using composer with my WP environment and have come across an issue with Menus. I am seeing that i can’t wrap menus into something that i can easily deploy across new environments as they are stored in the db upon creation via the gui. How are other people handling menus? I see there is a couple plugins out there but would rather not go down that route. I am also exploring checking in html menu items as part of a custom header.php file from my themes child-theme directory. The problem with this is easy of maintenance and not seeing or being able to easily update or view menu configs from the gui.

thanks

0 Likes

#2

You could filter the menu with wp_nav_menu_items() to add items programmatically, but also be able to use the gui for other items.

0 Likes

#3

You’ll need to figure out what workflow makes the most sense for you. What I usually do is:

  • Sync db/uploads between environments selectively, and/or…
  • Create migration scripts that are ran one time to handle performing database changes

The migration scripts usually just live in mu-plugins and check to see if an option the DB exists. If it doesn’t exist it’ll then perform some tasks. You could programmatically set create the nav menu and set the location like how we used to do it in the old Roots theme:

https://github.com/roots/sage/blob/7.0.3/lib/activation.php#L168-L206

0 Likes