Support » Fixing WordPress » Large Number of Custom Menu Items not Saving

  • Resolved jamesguy9



    I am having an issue when trying to save a custom menu (/wp-admin/nav-menus.php) and it takes 5-6 minutes to process, upon which it gives me a 404 Error afterwards. I’ve done a number of things to try and remedy this:

    1. Deactivate all plugins and the theme.
    2. Increase values within my php.ini file (max_execution_time = 300, max_input_time = 200, post_max_size = 100 etc.).
    3. Search various topics on Google.

    But have had no luck. Has anyone else encountered this and found a solution? The menu has 100+ items.

    Please let me know if you have any questions & thanks very much in advance.

Viewing 4 replies - 1 through 4 (of 4 total)
  • esmi


    Forum Moderator

    Sounds like you’re hitting a custom menu limitation issue.

    Thanks esmi,

    I’m trying to determine the fix from that ticket. There is a hack which is referenced, but where should it be included?

    I also noticed that there is a related fix posted in that ticket:

    There is a long bit of code on that page starting with “jQuery(function($) {“, where should this be placed? From its description, it should solve my issue.




    Forum Moderator

    You would need to enqueue the hack mentioned in but, ultimately, this is always going to be a server-related issue. Frankly, I cannot understand why anyone would want a custom menu with 100+ items. It goes against all usability recommendations.

    I found the solution!

    I used the code from here:

    I made the first fix the poster recommended and then I added the following code to line 468 of nav-menus.php:

    <script type="text/javascript">
    jQuery(function($) {
      // the currently displayed menu form
      var $form = $('#update-nav-menu');
      // Listen to new menus, since we have no possibility to hook
      // we have to interval it, because we can't capture an event here
      $('.submit-add-to-menu').click(function() {
        var $item_count = $form.find('.menu-item-handle').length;
        var $interval_id = setInterval(function() {
          var $current_item_count = $form.find('.menu-item-handle').length;
          if ($item_count < $current_item_count) {
            // Add the dirty flag and set it to dirty immediately
            // Reassign the mousedown/up events
      // add a hidden field, telling if the menu is dirty (by default, it's not)
      function add_dirty_flags($flag) {
        $form.find('.menu-item-handle').each(function() {
          if ($(this).find('.dirty-handle').length == 0) {
            var $html = '<input type="hidden" class="dirty-handle" value="' + $flag + '" />';
            console.log('flag added');
      // (re)assigns mouse events to menu items
      function assign_mouse_events() {
        var $menu_items = $('.menu-item-bar');
        // Unbind previously assigned events
        // Dirty Flag handler if a click happens
        $menu_items.mousedown(function() {
        // if the parent changes on release the mouse handle, change all items with the new parent to dirty
        $menu_items.mouseup(function() {
      // The call back for mouseup on menu bars
      function menu_save_mouseup($this) {
        var $temp_object = $this.parent();
        // Mark everything with the same parent dirty
        setTimeout(function() {
          var $parent_id = $temp_object.find('.menu-item-data-parent-id').val();
          // Go through all fields, dirtying everything that has the same parent
          $('.menu-item-data-parent-id').each(function() {
            if ($(this).val() == $parent_id)
      // On submit make every undirty menu an empty title, so it won't get saved
      // We're using a hoax in nav-menus.php, line 335 here..
      $form.submit(function() {
        // Now traverse all handles and make only dirties saveable
        $form.find('.menu-item-handle').each(function() {
          // Find the dirty flag
          var $is_dirty = $(this).find('.dirty-handle').val();
          if ($is_dirty == 0) {
            // The div containing the menu informations
            var $forms = $(this).parent().next();
            // Remove the title value so it doesn't get saved
        return true;
      // Assign mouse events on first load
      // Add all dirty flags (not dirty by default of course)

    This makes the menu actually save and do so quickly.

    It’s a very large site which, unfortunately, requires many nav items.

    Thanks again for your help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Large Number of Custom Menu Items not Saving’ is closed to new replies.