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
- Display a portion/ branch of the menu tree using wp_nav_menu()
- wp_nav_menu: show menu only if one exists, otherwise show nothing
- Add custom menu item using wp_nav_menu_items filter
- how to create a menu with all sub categories?
- Add separator to admin submenu
- Display only page specific sub menu items using Custom Walker
- Add child pages automatically to nav menu
- Show just one level of child pages, wp_list_pages woe
- Automatically remove trashed pages from nav menu
- Add a .last class to the last in each ul.sub-menu
- Multi Level Bootstrap Navigation Menu in WordPress
- Add class to top level menu item if it has multiple child levels
- How show sub menu only using wp_nav_menu()
- Show only 2nd level of navigation depending on active navigation
- Simple Navigation Walker – Wrapper-class around first sub-menu
- How to get a separate child menu?
- Exclude one item from wp_list_pages( $args );
- Directing a page to a default subpage
- wp_nav_menu() loses ‘current-menu-*’ classes on single product page within category
- How to drag multiple menu items at once in WordPress?
- Customizing the a tag with Semantic UI
- Can you have different menus and theme on a per-page basis?
- List children of second level sub page
- Put a wp_nav_menu inside another one
- Ways to give a wp_list_pages menu link specific class names?
- Add items to a menu dynamically
- How to get current page menu item name instead of full menu item list
- Generate a Menu that displays all child pages of top level parent
- Hide pages depending on role
- Get parent page/menu id of current post
- How can I add a sub menu to an existing navigation menu in WordPress?
- Custom Nav Walker sub-menu HTML construct
- Check if wp_nav_menu items have submenus
- wp_list_pages – show pages immediately 1 level below current level
- Add div to specific sub-menu
- Automatically Add New Tags to Sub-menu
- Change menu items URL
- Adding different classes to anchor in navigation menu
- Nav walker, bootstrap: Display 3rd level items under 2nd level
- how to only add a top-level admin menu without it creating a sub-level-menu
- how to automatically generate hierarchical menus from hierarchy of pages?
- 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
- Programmatically adding menu items function replicates in multiple menus
- Different side menu on each page
- Sub-Pages only of menu items in current branch using a custom menu
- No link on empty page in wp_list_pages
- WordPress – site with 2 stylesheets and more…
- Update Nav Menu Items Programmatically
- Remove Page Name From WordPress Menu
- Hiding Menu From Specific Pages
- How to display dynamic content in start_lvl function
- Getting post content within wp_nav_walker
- list pages only from master parent
- Menus like a CMS
- next_post_link() on custom menu structure
- WordPress sub-menu items suddenly not showing
- How to add a submenu toggle button inside all “li” elements that have a submenu?
- No “current-menu-ancestor” class added when browsing an archive page
- Main Menu and Sub Menu Items for Footer
- How to construct a custom html for submenus
- Auto add pages to primary menu with functions.php
- Check if menu id = $specific_id – then insert specific
- Show menu based on parent & ancestor
- WordPress menu permalink redirects to wrong page
- How to include a third level with wp_get_nav_menu_items function
- Highlight another nav item
- wp_nav_menu() with multiple Class
- Link to Homepage in Menu
- How do you manage large menu hierarchies in WP?
- Add class active to static menu
- Update body class based on menu
- add_submenu_page function to show videos table
- Trying to Create Menu in WordPress
- How do I add recent posts to the menu?
- How to add ID attribute to each submenu?
- Check if Page Already Exists in Menu
- Hierarchical menu nesting problem with jQuery targetting
- From a page, is it possible to find entry’s “menu_item_parent”?