• Resolved VM06

    (@vm06)


    Hello,
    I would like to automatically populate sub-menus depending on parent pages (or categories). I tried a good plugin called “Auto Submenu” but it does not automatically update the sub-menu when we change the parent after publishing the page (it only works when pages are added and not updated). Do you have any idea on how I can do to automatically add and update sub-menus depending on parent pages? Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator bcworkz

    (@bcworkz)

    Assuming the menu is output with a call to wp_nav_menu() (almost universally true, but it’s theme dependent), there are a number of filters in wp_nav_menu() that can be hooked to alter what’s in the menu. This does mean custom coding. Depending on what you really need to accomplish, this can be relatively simple or very complex.

    Probably the best filter in this situation is “wp_nav_menu_objects” which allows one to add, remove, or alter various objects of which the menu is composed.

    Thread Starter VM06

    (@vm06)

    Hello @bcworkz,
    Thanks for your answer.
    I tried many codes and plugins and nothing works.
    I am using WP Ocean Theme and it is not possible to automatically populate sub menus or child menus when we update a page (that is to say when we change the parent for a published page and not for a new page).

    Moderator bcworkz

    (@bcworkz)

    I’m sorry, I misunderstood exactly what you are trying to do, disregard my previous post. Menu items are stored as posts of the type nav_menu_item. If you hook “wp_insert_post_data” filter, you can decide if the page being saved is having its parent changed or not. If it is, manipulate the menu items as required. Off hand, I’m not familiar with exactly how the menu items are structured, but it shouldn’t be too hard to figure out by inspecting various elements through phpMyAdmin. As long as your theme is making use of the WP nav menu system, I believe this to be eminently doable.

    Thread Starter VM06

    (@vm06)

    Thanks for your answer, but I am afraid I will not be able to use those hooks due to limited knowledge in WordPress development.
    Thanks anyway.

    Moderator bcworkz

    (@bcworkz)

    I’m sorry my suggestion isn’t useful to you. I suppose you were hoping for a plugin recommendation. I’m sorry I cannot help with that. For all the plugins available, you’d think there would be something that fits your need. Yet so many specific needs require custom coding. There are even more coders doing this sort of work than there are plugins. You might consider hiring someone to help you. A couple possible resources for knowledgeable coders are jobs.wordpress.net and jetpack.pro.

    The fact is hooks in WP are essential to changing anything about how WP works. It’s fundamental to how all plugins work. If you have any interest in expanding your development knowledge, understanding hooks is an important step. If not, that’s fine too, it’s certainly not for everyone. Good luck in your search for a solution.

    Thread Starter VM06

    (@vm06)

    Thanks for your answer and your information about the websites for finding coders, I was thinking about that.
    And concerning hooks, I am learning every day, following my needs. But it is hard anyway.
    Thanks for your kindness,
    Regards.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Adding and updating submenu automatically’ is closed to new replies.