0

I've been reading through some of the questions and solutions people have already asked to no avail.

I have 4 menus on my WP Site, each of which will have children.

What I would like the menu to do is automatically add children to it and display it without me/someone else having to manage the menu pane.

For example:

  • About us
    • Child 1
    • Child 2
    • Child 3
    • Child 4

Where all the children pages are added as new pages, and set to have About Us as the parent.

As far as I understand now the only way is to use the menu pane. I've looked at Auto Submenu, Gecka Submenu and others, but they don't seem to help at all.

Any suggestions?

1
  • Have you considered using wp_nav_menu( $args ) WordPress function? It should do what you want to achieve!
    – sri
    Feb 5, 2014 at 9:14

2 Answers 2

1

There are two possible approaches you can take.

One would be to hook into whenever a Page is published and write code to update the menu accordingly, effectively making something similar to the built-in "add top level pages" functionality. You'd need to think carefully about what you would like to happen when the Page parent is changed and so on.

So perhaps more robust than that is to hook into menu rendering and if a Page has children, insert a sub-menu using wp_list_pages. I'm not up-to-date on hooks within the default menu Walker. Last time I looked at something like this I had to use my own Walker class as a callback on wp_nav_menu. Hopefully there are now more hooks you can use in there if you look at the source.

-1

You can use the [wp_nav_menu][1] function like so:

<?php 
    $args = array(
                'menu' => 'menu_name', //Name of menu you created in WP admin
                'depth' => 1, //define how deep you'd like the menu 0,1,2,3 etc
                'items_wrap' => '<ul><li id="item-id">Menu: </li>%3$s</ul>' 
            );
    wp_nav_menu($args);
?>
4
  • How would this work if I have 4 menus then? If I have one menu called About-us, information, how-to, contact-us?
    – Josh
    Feb 5, 2014 at 16:53
  • You can pass the 'menu' option to the $args array. I've edited my answer to include this.
    – Fraggy
    Feb 5, 2014 at 16:56
  • @josh has this solved your issue? Please mark as answered.
    – Fraggy
    Apr 23, 2014 at 14:07
  • This won't automatically add children to the menu Jun 15, 2016 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.