I play a lot with importing and exporting content lately. When I remove content, the created menu items need to be removed automatically. Here's a snippet on how to delete all links in a menu.

$mids = \Drupal::entityQuery('menu_link_content')
      ->condition('menu_name', 'custom-menu')
$controller = \Drupal::entityTypeManager()->getStorage('menu_link_content');
$entities = $controller->loadMultiple($mids);


Saved you some valuable time?

Donate and get more free time-saving code on this website in the future.