How to get titles for next and prev? wp_nav_menu


I have function which gets menu next and previous item url. I want to get also title for them. How can I do this? This is what i have :

$menu_name = 'main-menu';
$locations = get_nav_menu_locations();
$menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
$menuitems = wp_get_nav_menu_items( $menu->term_id, array( 'order' => 'DESC' ) );

foreach ( $menuitems as $item ):


  $id = get_post_meta( $item->ID, '_menu_item_object_id', true );
  $page = get_page( $id );
  $link = get_page_link( $id );


  if ($id==$post->ID){


if (empty($nextid)){
if (empty($previd)){

<a href="<?php echo $nextid; ?>">Next Item</a>
<a href="<?php echo $previd; ?>">Previous Item</a>

Destination point is to replace ‘next item’ and ‘previous item’ with wp_nav_menu’s next and prev item titles. Is that possible with this function? Any answer will be helpful!

, Sten Stmith 3 years 2020-07-16T08:11:32-05:00 0 Answers 30 views 0

Leave an answer