one snippet
https://www.isitwp.com/limit-amount-of-menu-items/
<?php
add_filter( 'wp_nav_menu_objects', 'mytheme_menufilter', 10, 2 );
function mytheme_menufilter($items, $args) {
// want our MAINMENU to have MAX of 7 items
if ( $args->theme_location == 'mainmenu' ) {
$toplinks = 0;
foreach ( $items as $k => $v ) {
if ( $v->menu_item_parent == 0 ) {
// count how many top-level links we have so far...
$toplinks++;
}
// if we've passed our max # ...
if ( $toplinks > 7 ) {
unset($items[$k]);
}
}
}
return $items;
}
?>