What is the easiest way to duplicate an entire navigation menu? I don’t care if it involves SQL commands or whatnot. I just have some really big menus that I’d like to duplicate. I didn’t see a plugin to do this.
For clarification, I want to duplicate the menu so I can make some edits to it and use it as a secondary menu elsewhere. I’m not trying to display the menu twice.
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_idwp_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
So I was struggling with a similar issue
I wanted to create lots of menus to displayed based upon permissions… lots of the items were duplicates etc so the easy way was likely to somehow copy something that already existed
I then needed to migrate all those menus to multiple blogs which share the same permissions.
But I am only a half-hearted programmer.
So this is the kludge solution but it seems to work, no programming required
WP has an export function – if you have a clean blog (and maybe even if you haven’t) it seems all the menu items get listed in the same part of the export file.
There are only 2 things (possibly) if you are dealing with a single blog that need to be changed, as posts and pages will be skipped anyway due to duplicate slugs
This is the definition for the menu’s custom category. You need to change the slug and the CDATA (where is says “FA” in my example)
<wp:term><wp:term_id>3</wp:term_id><wp:term_taxonomy>nav_menu</wp:term_taxonomy><wp:term_slug>FA</wp:term_slug><wp:term_name><![CDATA[FA]]></wp:term_name></wp:term>
Next you need to do a search and replace for all the menu items related to that slug / category.
<category domain="nav_menu" nicename="FA"><![CDATA[FA]]></category>
Again look for the “FA”
Save the XML with a nice clean filename.
Then you use the WP importer plugin to import the XML
YMMV but WFM and saved me a ton of time
Seriously quick & dirty but seemingly functioning alternative for DEV purposes only:
Disclaimer: This is only for developers who quickly want to make a proof-of-concept on something in a sandbox. Never do this on a database which you would like to preserve in a stable state in the future.
For instance, you’re referring to the same menu items in two menus, which probably is a bad idea in the long run. Also, you’re skipping all WP hooks which may or may not cause a number of undesired outcomes, depending on your case.
Friendly note: If you can’t find the menu id, you probably shouldn’t use this solution.