Rearranging MODX Main Menu Items

Moving things around on the MODX Manager's Main Menu.

By Bob Ray  |  September 30, 2025  |  2 min read
Rearranging MODX Main Menu Items

In this article, we'll look at how to change the order of the items in the MODX Main menu, and its dropdown menus.

The Problem

Maybe you don't like the order of the items in the MODX Main Menu or its dropdown menus. Maybe you want the Reports menu to come first, or you want to move the Clear Cache option out of the dropdown menu and put it on the top line, or you've added a custom menu item that lets you edit a particular page

The Solution

This is an easy one. Just go to the Menu section at System (gear icon) -> Menus. Then click and drag the menu items to their desired locations.

There's Always a Catch

The catch here is that whenever you upgrade MODX or run setup again, the menu items will go back to their default locations. If you've just moved one or two, this isn't a big deal, but if you've made extensive changes to the menus, it can be fairly annoying. There's a way around this problem, though. A long time ago, I wrote a couple of utility snippets, one to save the menu structure to a file, and one to restore it from the file.

Saving and Restoring

Saving and restoring your menu structure uses a pair of utility snippets, one to save, and another to restore the parent and menuindex fields.

One word of warning: the method may be unreliable if the text of any menu items had changed between the time you save your menus and the time you restore them. Nothing will be harmed if this happens (and it's not likely to). The menu items will still all be there, but any menu items with changed text just won't be reset to where you had them when you saved the menus.

SaveMenu Snippet

Create a snippet called SaveMenu with this code:

<?php
/* SaveMenu snippet */

/* Make this work in both MODX 2 and MODX 3 */
$prefix = $modx->getVersionData()['version'] >= 3
    ? 'MODX\Revolution\\'
    : '';

/* Get the menu item objects */
$menus = $modx->getCollection($prefix . 'modMenu');

$output = "\$menus = array(\n";
foreach ($menus as $menu) {
    $name = $menu->get('text');
    $parent = $menu->get('parent');
    $menuindex = $menu->get('menuindex');

    $output .= "\n    \$" . $name . "= array(\n";
    $output .= "\n        'parent' => " . "'" . $parent . "',\n";
    $output .= "\n        'menuindex' => " . "'" . $menuindex . "',\n";
    $output .= "\n    ),";

}
$output .= "\n);";

$fp = fopen('saved_menus.txt', 'w');
fwrite($fp, $output);
fclose($fp);

RestoreMenu Snippet

Now create a second snippet called RestoreMenu with this code:

<?php
/* RestoreMenu snippet */

/* Make this work in both MODX 2 and MODX 3 */
$prefix = $modx->getVersionData()['version'] >= 3
    ? 'MODX\Revolution\\'
    : '';

/* Get the saved menu data */
include 'saved_menus.txt';

foreach ($menus as $name => $fields) {
    $output = "\n### Restoring Menus";
    $menuObj = $modx->getObject('modMenu', array('text' => $name));
    if ($menuObj) {
        $menuObj->set('parent', $fields['parent']);
        $menuObj->set('menuindex', (integer) $fields['menuindex']);
        if ($menuObj->save()) {
            $output .= "\n<br />Restored Menu: " . $name;
        } else {
            $output .= "\n<br /> Could not save menu: " . $name;
        }
     } else {
        $output .= "\n<br />could not find menu: " . $name;
    }
}

SaveMenu and RestoreMenu Resources

Next, create two resources called SaveMenu and RestoreMenu. You'll probably want them hidden from menus, and if you're the admin Super User, there's no need to publish them. Put this tag in the SaveMenu Resource:

[[!SaveMenu]]

Put this tag in the RestoreMenu Resource:

[[!RestoreMenu]]

Operation

Before upgrading or reinstalling MODX, right-click on the SaveMenu Resource in the manager and select "View." That will save your menu structure

After the upgrade, do the same with the RestoreMenu Resource. That should put your menu back the way you like it.


Bob Ray is the author of the MODX: The Official Guide and dozens of MODX Extras including QuickEmail, NewsPublisher, SiteCheck, GoRevo, Personalize, EZfaq, MyComponent and many more. His website is Bob’s Guides. It not only includes a plethora of MODX tutorials but there are some really great bread recipes there, as well.