A couple of previous questions have touched on this topic (how to add menu items, how to hide menu items), but I'm trying to figure out how to remove or empty a menu and then programmatically refill it. It seems like the task has three parts:

  1. How do you delete an entire menu? Previous answers to manipulating menu items point to JNestedTable for menu manipulation, but I don't see a function for accomplishing this--only for deleting a generic row from a table using a primary key value. I could do this outside of the Joomla Framework using a SQL query, but I suspect that is the wrong approach (because it will mess up the lft and rgt values):

    DELETE FROM menu WHERE menutype='name'

  2. How do you add menu items? I believe this was answered here, but any other thoughts?

  3. Once the menu is deleted and new menu items are added, how do you rebuild the menu? I know you can rebuild menus from the backend, but how can you do it programmatically?

Thanks so much!

1 Answer 1


You are probably best looking at com_menu and studying how core Joomla does it.

For deleting and adding entire menus, you can see the relevant functions at \administrator\components\com_menus\models\menu.php.

Here there is a function called delete, to which you pass an array of menu IDs, and it deletes them one at a time in a foreach loop. It's well commented, though does have the ominous comment // TODO: Delete the menu associations - Menu items and Modules at the end.

It also has a function to save here, which creates or edits menus. Here you pass the relevant data to match the fields at administrator\components\com_menus\models\forms\menu.xml. Send it an id of 0 if it is a new menu.

The rebuild function is found under \administrator\components\com_menus\models\item.php. This isn't well annotated, but it looks like JTable has a function for rebuilding.

This file also has the save function for menu items, which works in a similar way to the way the menu one worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.