Include Section in <head> tag = "HTML error found Broken HTML has been detected"

joseph-dc
Shopify Partner
4 0 2

We are creating a landing page for a client which requires custom metadata to be served and curated. The Open Graph description field for example should be defined in the Shopify Admin panel for that specific page. Our solution is to pull a section into a the head tag of a custom layout file. The problem is all sections include a div wrapper. We have overcome that problem by capturing the contents of the section then doing a liquid string replace on the opening and closing section div tags. This works perfectly but results in a cryptic invalid HTML error from Shopify in the Admin ui. 

HTML error found

Broken HTML has been detected in your theme's sections/crocs-head.liquid  file. Check that there are no missing or extra HTML tags present.
If you haven't made changes to this code, contact support for help resolving the issue.

Finally I've run the resulting page through the W3C validator and found no relevant HTML errors. I believe Shopify may be looking for that div to be present during validation and if not found they show the HTML error in the Admin UI. This is not the end of the world but can obviously be alarming to our client at first. I'm also open to other solutions if possible. Thanks in advance!



Screen Shot 2021-07-05 at 6.15.17 PM.png

We have also created an example store using the default theme to illustrate the issue.

https://dc-poc-include-section-in-head-tag.myshopify.com/

Reply 1 (1)

iDoThemes
Trailblazer
207 43 91

A store I'm working with does something similar with a section, though I'm planning to rip it out and use a snippet instead and theme settings to fill the variables. I don't think you'll be able to avoid this error with the current method you are using.  Is there something specific from the functionality of a section you need that a snippet + settings can't provide?

Developer of Liquify Chrome Extension -- Enhance the Shopify Theme Code Editor
.




Theme Developer -- Drop me a line