Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_filter( 'wp_nav_menu_objects', 'baw_nav_menu_objects', 10, 2 );
- function baw_nav_menu_objects( $items, $args ) {
- static $duplicate_menus = array();
- if ( isset( $args->theme_location, $duplicate_menus[ $args->theme_location ] ) ||
- isset( $args->menu->term_id) && in_array( $args->menu->term_id, $duplicate_menus ) ) {
- $current = 0;
- $new_items = array();
- foreach ( $items as $item ) {
- if ( ! $item->menu_item_parent && ( $item->current || $item->current_item_ancestor ) ) {
- $current = $item;
- reset( $items );
- foreach ( $items as $item ) {
- if ( $item->menu_item_parent == $current->ID ) {
- $new_items[] = $item;
- }
- }
- break;
- }
- }
- ////array_unshift( $new_items, $current ); // laisser ou pas le menu parent
- if ( $current ) { // vider ou pas le menu
- $items = $new_items;
- }
- }
- if ( ! empty( $args->theme_location ) ) {
- $locations = get_nav_menu_locations();
- $duplicate_menus[ $args->theme_location ] = $locations[ $args->theme_location ];
- }
- return $items;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement