This would probably be better achieved using CSS. First, you hide all .children:
.page_item .children {
display: none;
}
Then, you show the current_page_item’s children:
.current_page_item .children {
display: block;
}
Related Posts:
- How to make pages metabox display all hierarchy in menu admin?
- Handling complex multi-level architecture / menu for large site
- wp_list_pages sort order is different for different languages [closed]
- How to have custom menu Item CSS Classes for wp_page_menu() or wp_list_pages()
- Does loading of sub pages in menu cause load to the server?
- Schedule Page to Menu [duplicate]
- wp_list_pages() but only show children on the branch you are on
- How to retrieve parent menu item name of current submenu item
- Displaying different page links on different pages
- How to highlight 1st level menu item based on actual page
- Add (grand)child pages automatically to nav menu
- Get parents child pages
- Dynamic menu wp_list_pages displaying only current branch including: current page, his siblings and its childs
- wp_list_pages Hierarchical Help
- Add CSS Class to WordPress Menu Item Dependent on the Page the User is Visiting
- Creating navigation out of specific IDs and their children?
- how to create pages and link them to a menu
- How to sort a sub-menu, generated with get_pages(), by the page order instead of alphabetically?
- How to display list of child pages with parent in wordpress?
- Display all submenus
- Add custom menu item using wp_nav_menu_items filter
- how to create a menu with all sub categories?
- Add separator to admin submenu
- Show just one level of child pages, wp_list_pages woe
- How show sub menu only using wp_nav_menu()
- Show only 2nd level of navigation depending on active navigation
- Can you have different menus and theme on a per-page basis?
- List children of second level sub page
- Add items to a menu dynamically
- How can I add a sub menu to an existing navigation menu in WordPress?
- Add div to specific sub-menu
- Adding different classes to anchor in navigation menu
- Custom Walker for Walker_Nav_Menu
- Arrow down in menu not displaying
- Making WordPress’ page and menus visible only for logged in users, checking session variables
- Different side menu on each page
- WordPress – site with 2 stylesheets and more…
- Update Nav Menu Items Programmatically
- Getting post content within wp_nav_walker
- next_post_link() on custom menu structure
- How to add a submenu toggle button inside all “li” elements that have a submenu?
- Auto add pages to primary menu with functions.php
- Show menu based on parent & ancestor
- How to include a third level with wp_get_nav_menu_items function
- How do you manage large menu hierarchies in WP?
- Add class active to static menu
- Update body class based on menu
- Check if Page Already Exists in Menu
- two different separate sections on the same site
- When clicking on menu item not going to specific page
- Add code to WordPress menu items by class
- How to customize submenus isn wordpress theme [closed]
- wp_list_pages sort order by custom nav menu order
- Can I have a different menu for each parent page?
- Prevent menu from loading in a page template [duplicate]
- remove class “sub-menu” from wordpress drop down menu
- Add a submenu to wp_nav_menu
- Wrap list parent in div with wp_nav_menu menu
- Three menus – parent / child / sibling
- sub menu link is not working
- Adding toggle-able element after menu item
- Disable parent in wp_list_pages – WordPress
- URL links consistent with menus?
- I can’t add more pages to menu – menu delete pages
- Wp_list_pages not showing children with custom page template
- How to check if current page is a parent item or child item in a given menu
- Removing Submenu from Menu
- Controlling sub-menu within sub-menu
- Main menu navigation links and new pages
- wp_list_pages() not showing on posts
- horizontal menu / 4-level depth
- Set one or more menus as a submenus of another menu
- Custom menu with additional logic for display
- How to get the Page Name of the current page?
- Change hover to onclick on menu
- Bootstrap Theme Migrated to WordPress
- having a page in multi sub-menu and match current-menu-item
- Why my dropdown menu is effecting main menu?
- How can I order these pages in this navigation bar on this old wordpress theme?
- Where to place a svg chevron down in my custom walker?
- Add href to tag in nav menu for mobile
- How to access into the description of a sub menu
- Adding span to a particular text in an menu item
- Unable to remove page from primary menu
- How to separate sub-menu output and keep associated with parent
- Has there been any improvements to wp’s menu handling?
- Always show wordpress submenu on responsive header menu
- Show Child of Parent Page including all other parents
- nav_menu: how to force a subpage switching on the parent menu
- Use menu structure for permalinks
- Creating and populating custom nav menu (menu-item-position not working)
- How to make a page to not appear in the menu when created?
- Add tooltips with image in WordPress Menu?
- Building Menus with the latest posts included
- How to add drop down sub menu from database fields in the particular menu slug
- wp_nav_menu changed to wp_page_menu
- Should I custom code drop down menus or use a wordpress plugin?
- WordPress menu is getting automatically nested
- What is the best way to incorporate responsive dropdown navigation menu into custom theme?
- Give custom class names to WP nav sub-menu