The Hidden Header Mystery: How Commented Liquid Code Can Duplicate Your Shopify Storefront Sections

Ever hit a wall with a Shopify bug that just doesn't make sense? You've checked everything, and the platform seems to be doing something completely unexpected. That's exactly the kind of head-scratcher one of our community members, CW5, recently faced. After a custom mega-menu rebuild, their store's header section started rendering three times sitewide – not just in the raw HTML, but even in the Theme Editor!

What made it even trickier? Shopify Support, while helpful, confirmed it was out of scope for their heavily customized theme. This is a common scenario for many of you running bespoke setups. But thanks to some sharp community minds, we peeled back the layers on this one, and the solution is a fantastic lesson for anyone dabbling in Shopify theme code.

The Mystery Unfolds: What We Thought It Was

CW5's initial problem was clear: one {% section 'header' %} call in their theme.liquid, but three identical header sections appearing everywhere. The extra headers weren't even visible to shoppers, but they were bloating page weight and causing invalid duplicate element IDs – a big no-no for SEO and accessibility.

They did all the right things, systematically ruling out common culprits:

  • Duplicate Calls: Exhaustively searched all layout files (including hidden ones like theme.aftership.liquid) – only one {% section 'header' %} remained.
  • Third-Party Apps: Disabled apps one by one – no change.
  • Cache Issues: Even a brand-new duplicate theme showed the same problem.
  • Section Complexity: Reducing the number of blocks or block types in the mega-menu schema made no difference.
  • OS 2.0 Group Conflicts: Checked for header-group.json or {% sections 'header-group' %} calls – none existed.
  • Nested Snippets: Scoured snippets for rogue {% section 'header' %} tags – nothing.
  • settings_data.json Orphans: Confirmed only one real header instance in the config.

It was a truly baffling situation, as CW5 noted, feeling like "something about how this file interacts with the rest of the (heavily customized) theme."

The Crucial Clue: Raw HTML vs. Live DOM

A significant turning point came when CW5 compared the raw server HTML (which showed 3 header wrappers) with the live browser DOM after the page loaded (which showed only 1). This led to a theory: some client-side script was quietly cleaning up the extra copies. Our community expert, MayraApps, jumped in with a clever diagnostic script:

This script, placed in your , would pause execution if any script actually removed a section. It's a fantastic tool for debugging such mysteries! However, in this case, it came back clean – meaning no script was removing anything. The two extra headers were never real DOM elements to begin with.

The "Aha!" Moment: Comments Aren't Always Just Comments

This is where community member Ploqo delivered the breakthrough. By directly inspecting the store's source code, they found the two extra header markups were sitting inside CSS comments!

Two of the three are header markup pasted into CSS comments

Ploqo's analysis showed that while the HTML source code listed three instances, the browser's live DOM only recognized one. This was confirmed by running document.querySelectorAll('[id="shopify-section-header"]').length in the console, which returned '1'.

Source shows 3, the live DOM shows 1

The kicker? CW5 then realized that two of their own documentation comments, explaining CSS decisions, had quoted the literal {% section 'header' %} code inline as an example. And here's the critical insight, as MayraApps eloquently explained: Shopify's Liquid engine executes {% %} tags anywhere in a file, including inside what looks like a CSS comment or an HTML comment! To Liquid, it's all just characters to be processed before the browser even sees it.

This meant the extra headers weren't inert phantom text; they were real, live code being executed and rendered by Liquid, even if trapped within a