If a new page is added under a parent page (front end), which is part of a nav menu, I want the new page to be added to the appropriate submenu automatically - without any plugin.
Reason: A custom user role has all caps to add, edit, delete posts and pages. However, this role shall not be capable to enter Design settings where Menu settings are part of. In my custom template, sub-pages simply should appear in the sub menu of their respective parents.
I understand, that I need to hook into the nav_menu render process. I guess, the first answer here is pretty close to a solution. However, I can't find the proper hook nor exactly how to hook in.
I fiddled around with wp_nav_menu_items
but can't make sense of it, as the hook's callback function doesn't accept any parameters, does it?
That's my pseudo code to explain my intention:
function add_subpages_to_submenu($Menu){
foreach ($Menu->Items as $Item) {
if ($Item->hasChildren()){
foreach ($Item->Children as $Child) {
add_to_current_submenu($Child);
}
}
}
return $Menu;
}
add_filter('wp_nav_menu_items', 'add_subpages_to_submenu');
What needs this code to look like actually?
Thanks!