Remove All Items from a Wordpress Navigation Menu by Code

If you want to remove all items from a WordPress navigation menu, you may be have to do a lot of clicks. Another option might be using this code snippet:

$menu_id = 12345 // modify this!

function cleody_empty_menu($menu_id)
    $items = wp_get_nav_menu_items($menu_id);

    foreach ($items as $item) {


All you have to do is to modify the $menu_id variable and then add this code to your functions.php (or somewhere else, where it gets executed). After menu cleanup, you have to remove this code (or comment it out) – otherwise the menu gets wiped every time you open a page. As an addition you may add a special trigger, so the menu get wiped only if there is a special GET parameter, an option variable or something else.