Advertisement
Guest User

Untitled

a guest
May 4th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. <?php
  2.  
  3. add_filter( 'wp_nav_menu_objects', 'baw_nav_menu_objects', 10, 2 );
  4. function baw_nav_menu_objects( $items, $args ) {
  5.     static $duplicate_menus = array();
  6.     if ( isset( $args->theme_location, $duplicate_menus[ $args->theme_location ] ) ||
  7.         isset( $args->menu->term_id) && in_array( $args->menu->term_id, $duplicate_menus ) ) {
  8.  
  9.         $current = 0;
  10.         $new_items = array();
  11.         foreach ( $items as $item ) {
  12.             if ( ! $item->menu_item_parent && ( $item->current || $item->current_item_ancestor ) ) {
  13.                 $current = $item;
  14.                 reset( $items );
  15.                 foreach ( $items as $item ) {
  16.                     if ( $item->menu_item_parent == $current->ID ) {
  17.                         $new_items[] = $item;
  18.                     }
  19.                 }
  20.                 break;
  21.             }
  22.         }
  23.  
  24.         ////array_unshift( $new_items, $current ); // laisser ou pas le menu parent
  25.         if ( $current ) { // vider ou pas le menu
  26.             $items = $new_items;
  27.         }
  28.     }
  29.     if ( ! empty( $args->theme_location ) ) {
  30.         $locations = get_nav_menu_locations();
  31.         $duplicate_menus[ $args->theme_location ] = $locations[ $args->theme_location ];
  32.     }
  33.  
  34.     return $items;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement