> For the complete documentation index, see [llms.txt](https://raia-software-inc.gitbook.io/tacview-2-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://raia-software-inc.gitbook.io/tacview-2-documentation/api-reference/api-reference/menus/remove-menu-item.md).

# RemoveMenuItem()

Removes an item from a menu.

## Syntax

```lua
RemoveMenuItem(menuHandle, itemId)
```

## Parameters

### `menuHandle`

Handle of the menu to modify.

This is typically a handle returned by a function such as `GetMainMenuHandle()`.

### `itemId`

String id of the menu item to remove.

The id must match the `id` field used when the item was added with `AddMenuItem()`.

## Return value

This function does not return a value.

## Remarks

`RemoveMenuItem()` removes the item identified by `itemId` from the menu hierarchy identified by `menuHandle`.

A menu handle identifies one complete menu hierarchy. This hierarchy may contain items and submenus. Item ids are unique inside that hierarchy, and the same item id may be reused in another independent menu.

Menu items are removed by id, not by path. This means that the item can be removed even if its label, icon, or group has changed, as long as its id remains the same.

If the item has child items or a submenu, removing the item also removes the whole subtree below that item.

If the item does not exist, or if it has already been removed, `RemoveMenuItem()` has no visible effect.

If the menu handle is valid but the item id does not match any item in the menu, `RemoveMenuItem()` has no visible effect.

Wrong argument types raise the usual script error. Logical errors, such as an unknown item id, have no effect and do not corrupt existing menu data.

Add-ons should remove items added to shared menus when the add-on shuts down. This includes global menus such as the main menu or common context menus. This prevents Tacview from keeping inactive commands visible if the add-on is disabled or unloaded while Tacview continues running.

It is usually not necessary to remove items from menus owned only by the add-on itself, such as menus that belong to a viewport or window that will be destroyed with the add-on.

## Example

This example adds a menu item during initialization and removes it during shutdown.

```lua
local DogfightAnalysisMenuId = "DogfightAnalysis"

function PluginInitialize()

	local mainMenuHandle = GetMainMenuHandle()

	if mainMenuHandle then

		AddMenuItem(mainMenuHandle, {
			path = "Analysis",
			group = "Charts",
			id = DogfightAnalysisMenuId,
			label = "Dogfight Analysis"
		})

	end

end

function PluginShutdown()

	local mainMenuHandle = GetMainMenuHandle()

	if mainMenuHandle then

		RemoveMenuItem(mainMenuHandle, DogfightAnalysisMenuId)

	end

end
```

## Example removing a submenu

This example removes a parent item. If that item owns a submenu, the submenu content is removed with it.

```lua
RemoveMenuItem(mainMenuHandle, "DogfightAnalysis")
```

## See also

* `GetMainMenuHandle()`
* `AddMenuItem()`
* `WasMenuItemClicked()`
