Programmatically disabling menu item I have been trying to disable a menu item "standard.front_page" using the following code:

db_query("UPDATE {menu_tree} SET enabled = 0 WHERE id LIKE 'standard.front_page';");
db_query("DELETE FROM {cache_menu};");


It works fine till I do a cache rebuild using drush cr. Once I do a cache rebuild the menu item again comes back.

Can anyone please suggest a good way of doing the above?
You can retrieve the Drupal menu link &amp; cache services to programmatically change the menu link status. Something like this example function:

function menu_state_toggle($menu_id, $enabled = TRUE) {
  $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
  $front_page_link = $menu_link_manager-&gt;getDefinition($menu_id);
  $front_page_link['enabled'] = $enabled ? 1 : 0; 
  $menu_link_manager-&gt;updateDefinition($menu_id, $front_page_link);
  $cache = \Drupal::cache('menu');
  $cache-&gt;deleteAll();
}

menu_state_toggle('standard.front_page', FALSE);