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.jsonor{% sections 'header-group' %}calls – none existed. - Nested Snippets: Scoured snippets for rogue
{% section 'header' %}tags – nothing. settings_data.jsonOrphans: 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!

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'.

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 block and thus not visually displayed by the browser. This also perfectly explained why the Theme Editor showed three linked, identical section instances – because Liquid had genuinely rendered that section three times!
Your Action Plan: How to Avoid This Pitfall
This thread offers some invaluable lessons for any Shopify store owner or developer working with custom themes. Here's how you can prevent or fix similar issues:
1. Inspect Your Store's Source and Live DOM
Always compare what your browser's "View Source" shows with what the developer tools' "Elements" tab (the live DOM) displays. If there's a discrepancy, you know where to start looking. You can use:
- The browser console:
document.querySelectorAll('[id="shopify-section-header"]').length - Or, for raw server output:
curl -s https://yourstore.com | grep -n 'shopify-section-header'
2. Check Your Comments for Executable Liquid
This was the core problem! Search your theme files (especially custom CSS or JavaScript files that might be .liquid files) for any instances of {% section '...' %} or {{ '...' }} that might be inside comments. The fix for CW5 was simple: rewrite the comments in plain English instead of quoting the literal code.

3. Use Liquid's Own Commenting Tools
To safely comment out or display Liquid code without execution, use Liquid's dedicated tags:
{% comment %} ... {% endcomment %}: For multi-line Liquid comments that prevent execution.
{% comment %}
This section call is for documentation only and should not run:
{% section 'header' %}
{% endcomment %}
{% raw %} ... {% endraw %}: To print Liquid code as plain text without running it. Perfect for showing examples in your code comments.
{% raw %}
This is how you'd call the header section:
{% section 'header' %}
{% endraw %}
4. Review All Layout Files for Duplicate Section Calls (General Best Practice)
While not the root cause in CW5's final discovery, it's always good practice to ensure only your main theme.liquid (or a designated layout file) calls your static sections like the header. As CW5 found, some themes have multiple layout files (e.g., theme.aftership.liquid, theme.gempages.header.liquid) that might inadvertently include their own {% section 'header' %} calls. When testing changes in the Theme Editor, remember to use a fresh incognito window, as the editor can sometimes hold onto old state.
5. Be Mindful of Asset Files with a .liquid Extension
MayraApps pointed out that this "Liquid in comments" behavior can bite you in asset files too. If you have a file named something like base.css.liquid, the Liquid engine will process it before it's delivered as CSS. So, be careful with any Liquid tags in comments within these files as well.
This particular mystery highlights a critical aspect of working with Shopify's Liquid engine: it processes code first, regardless of whether it's wrapped in HTML or CSS comments. Understanding this execution order is key to debugging those truly baffling issues in highly customized themes. It's a testament to the power of community collaboration that such a tricky, deeply technical problem could be solved, turning a frustrating bug into a valuable learning experience for everyone. Always remember, the devil's often in the details, especially when it comes to how your code is interpreted!