Get WP Nav Item top parent

function get_nav_menu_top_parent($menu_name){
global $post;
$items = wp_get_nav_menu_items($menu_name);
foreach($items as $item){
if($item->menu_item_parent == 0 ) $parent_name = $item->title;
if($item->object_id == $post->ID) $top_parent = $parent_name;
}
return $top_parent;
}

0 Comments

You must be logged in to post a comment.