What’s the easiest way to duplicate an entire navigation menu?

UPDATE:
The “easiest” way is to use my new plugin: http://wordpress.org/extend/plugins/enhanced-menu-editor/

It’s not approved yet, but once it is I’ll publish the widget. Not only does it allow for copying menus, but you can also synchronize the menu structure you establish in the menu editor to the page heirarchy of the pages themselves. So you can use drag-n-drop ajax coolness instead of editing potentially hundreds of pages manually.

OLD ANSWER:

The “easiest” way is to use code. There are two functions you’ll want to use:

wp_create_nav_menu() which creates the menu itself and returns the menu_id
wp_update_nav_menu_item() which will create a new menu item if you pass in 0 for the menu item id param.

Then you could use a wp_nav_menu walker class to iterate over each of the existing items in a menu. This website will give you a good reference point to start with that.

http://www.kriesi.at/archives/improve-your-wordpress-navigation-menu-output

So you call the create nav menu function first.

Then implement the nav walker on a given page. Inside your walker class’s start_el function, you’ll have access to the $item param that will allow you to call wp_update_nav_menu_item() with identical properties as the existing menu, but just pass 0 instead of the item’s real id, which will create a new menu item.

The only other property you’ll need to consider is the menu-item-parent-id because you’ll want that to reference your newly created menu item and not the old one on the other menu. For this you’ll need to create an array that keeps track of old id’s to new id’s.

If you’d like a concrete example of this solution just email me at marcuspope.com and I’ll see what I can whip up.

Hope that helps!
-Marcus

Leave a Comment