Minghui Yu
Minghui Yu

Reputation: 1363

Create menu items automatically when creating a page in WordPress. How to?

For Wordpress, when creating a page, a menu entry will be added to top level menu automatically. I have disabled this feature because it is not what I what.

What I want is, like Drupal, when creating a page, I can have a dropdown select to select which menu to add this page to and to which parent.

Which plugin can do that?

Thank you.

Upvotes: 1

Views: 2711

Answers (1)

karevn
karevn

Reputation: 575

You can do it yourself. What you need to do is:

  1. Use add_meta_box to add a meta box to your post editor. In that meta box, build a list of available menus using results from get_registered_nav_menus() function.
  2. Add a hook to save_post action, which will create a menu item.
  3. Create a menu item by calling wp_save_nav_menu_items($menu_id, $item_data)

It is not a piece of cake, but you can do it in a couple of hours.

Upvotes: 2

Related Questions