Since WordPress 3.0 was released we’ve had quite a few inquiries about the possibility of having the same menu across a network. This morning I had a bit of time to pull together a small plugin that accomplishes that. Basically what it does is cache a menu on the main site and display it on the subsites.
Sub Site Requirements
Each of the sub sites must:
- be using a theme that registers WP nav menus.
- have at least one menu with one or more menu items. The
wp_nav_menu()function exits early without displaying a menu if it does not find a menu with menu items.
- have a nav menu assigned to the specified slot. It can be an empty menu. The reason for this is the same as the previous limitation.
Main Site Implementation
- Create your network menu in the main site.
- Assign it to the chosen menu slot.
- Populate your chosen menu on the main site.
- Load the front end of the main site.
The reason for the last step is that each time you change a menu item on the main site a flag is set to flush the cached menu. The cached menu is refreshed the next time the menu is generated on the main site. Download: Networkwide Menu (5474)
Customizing for your use
- Network wide – I made it a network wide plugin. If you want to activate it only on specific subsites, then remove the
Network: trueline in the plugin header.
- Menu slot – the first line of code below the copyright notice is
$slot = 1;. The $slot variable is used to determine which menu slot to use when replacing the menu. As far as this plugin goes, menu slots are determined by the order in which they are registered by the theme. The first menu location registered is slot 1. The second menu registered is slot 2 and so on.