gohugoio/hugo · warning

duplicate menu entry with identifier %q in menu %q

Error message

duplicate menu entry with identifier %q in menu %q

What it means

Produced while assembling menus (hugolib/site.go:1487) when two pages define menu entries that resolve to the same KeyName (identifier, or name if no identifier) within the same menu. Hugo logs it as a warning via p.wrapError and skips the duplicate entry rather than failing the build, keeping the first entry seen.

Source

Thrown at hugolib/site.go:1487

					Name:       p.LinkTitle(),
					Weight:     p.Weight(),
				},
				Page: p,
			}

			navigation.SetPageValues(&me, p)
			flat[twoD{sectionPagesMenu, me.KeyName()}] = &me
			return false, nil
		}); err != nil {
			return nil, err
		}
	}

	// Add menu entries provided by pages
	if err := s.pageMap.forEachPage(pagePredicates.ShouldListGlobal, func(p *pageState) (bool, error) {
		for name, me := range p.pageMenus.menus() {
			if _, ok := flat[twoD{name, me.KeyName()}]; ok {
				err := p.wrapError(fmt.Errorf("duplicate menu entry with identifier %q in menu %q", me.KeyName(), name))
				s.Log.Warnln(err)
				continue
			}
			flat[twoD{name, me.KeyName()}] = me
		}
		return false, nil
	}); err != nil {
		return nil, err
	}

	// Create Children Menus First
	for _, e := range flat {
		if e.Parent != "" {
			children[twoD{e.Menu, e.Parent}] = children[twoD{e.Menu, e.Parent}].Add(e)
		}
	}

	// Placing Children in Parents (in flat)

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Give each page's menu entry a unique identifier in front matter (identifier: about-us).
  2. If names collide intentionally, add distinct identifier fields so KeyName differs.
  3. When using sectionPagesMenu, remove manual front-matter menu entries for those section pages.
  4. Search content front matter for the duplicated identifier: grep -r 'identifier:' content/

Example fix

# before (two pages)
menus:
  main:
    name: About
# after (page 2)
menus:
  main:
    name: About
    identifier: about-company
Defensive patterns

Strategy: validation

Validate before calling

seen := map[string]bool{}
for _, e := range menuEntries {
    key := e.Menu + "|" + e.Identifier
    if seen[key] {
        return fmt.Errorf("duplicate identifier %q in menu %q", e.Identifier, e.Menu)
    }
    seen[key] = true
}

Prevention

When it happens

Trigger: Two or more pages with front matter menu definitions (menus: main with the same identifier, or same name and no identifier) in one menu; also a page menu entry colliding with an entry auto-generated by sectionPagesMenu.

Common situations: Copy-pasted front matter archetypes leaving identical menu identifiers, sectionPagesMenu combined with manual page menu entries for the same sections, or translated pages in a misconfigured multilingual setup both registering into one menu.

Related errors


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/f7f8b95d3135c24f.json. Report an issue: GitHub ↗.