Not able to get current menu ID

As far as I’ve seen a menu object does not have the ‘current’ property, does it? Not that I ever seen it, at least. So you can get close to what you’re asking by comparing the current post/page ID (get_the_ID()) with the items’ object_id property, when they match – boom! you got your currently selected menu.

function wpse25992_store_current_id( $items, $menu, $args ) {
    foreach ( $items as $key => $item ) {
        // this is the currently displayed object
        if ( $item->object_id == get_the_ID() )
            $_SESSION['current_menu_title'] = $item->title;
    }

    return $items;
}
add_filter( 'wp_get_nav_menu_items', 'wpse31748_exclude_menu_items', null, 3 );

Leave a Comment