-
Within each menu item,
object_id
holds the ID of whatever object
the menu item refers to. This will be a post / page / CPT / term ID. If it’s a custom link, the ID refers to itself. (If you want to know what type of object it is,object
contains that.) -
get_queried_object_id()
will give you the ID of the current page. -
We can use the API function
wp_filter_object_list()
to filter out any menu items where theobject_id
doesn’t match the
queried object. -
We’ll then be left with an array containing a single element, so we
use php’scurrent
so that$this_item
now contains just the
matching menu item object. -
and finally,
title
holds the name we’ve given the menu item.
$menu_items = wp_get_nav_menu_items( 'main-menu' );
$this_item = current( wp_filter_object_list( $menu_items, array( 'object_id' => get_queried_object_id() ) ) );
echo $this_item->title;
Note- I didn’t test this, so hopefully it works!