Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. <?php
  2.  
  3. // Call function with ID of wanted menu, for example 'main-menu'
  4. function cleanmenu( $menuID ) {
  5.  
  6. $menu = array();
  7.  
  8. foreach ( wp_get_nav_menu_items( $menuID ) as $link ):
  9.  
  10. $menu[ $linkki->ID ] = array(
  11. 'title' => $link->title,
  12. 'url' => $link->url,
  13. 'is_children' => false,
  14. 'has_children' => false,
  15. 'childrens' => array()
  16. );
  17.  
  18. if ( $link->menu_item_parent !== '0' ): // Launch if menu-item has parent item
  19. $menu[ $link->ID ][ 'is_children' ] = true;
  20. $menu[ $link->menu_item_parent ][ 'has_children' ] = true;
  21. array_push( $menu[ $link->menu_item_parent ]['childrens'], $link->ID );
  22. endif;
  23.  
  24. endforeach;
  25.  
  26. return $menu;
  27.  
  28. }
  29.  
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement