A user is attempting to display a conditional link in their site’s dropdown menu that only appears for logged-in customers with a specific metafield value. The link should direct to a wholesale order form.
Core Issue:
The original implementation using metafield_tag filter was breaking HTML structure, rendering the link as a <p> tag instead of a properly formatted anchor element.
Root Cause Identified:
The metafield was defined as “Rich text” type, which automatically wraps content in paragraph tags. The metafield_tag filter produces different HTML elements depending on metafield type and cannot be used directly within href attributes.
Recommended Solution:
Redefine the metafield as “URL” type (or alternatively “Single line text” or “Page reference”). Then use:
Current Status:
The user tested the URL-type solution but reported it didn’t display in the menu. The discussion remains open with troubleshooting ongoing. The feature is described as non-critical, though the user would prefer to resolve it properly rather than use CSS workarounds.
Summarized with AI on November 9.
AI used: claude-sonnet-4-5-20250929.
Not sure if the title makes sense, but I am basically trying to add a link that only appears to certain customers once they have logged into their account on my site.
I have added my own code below:
{% if customer.metafields.custom.wholesale_order_form != blank %}
<a class="popover__link-item" href={{customer.metafields.custom.wholesale_order_form | metafield_tag}}>{{ 'Wholesale Order Form' }}</a>
{% endif %}
Into the existing code for the menu system on my site, as seen below:
My only issue is that using {{customer.metafields.custom.wholesale_order_form | metafield_tag}} after the href= doesn’t work as it is intended to. Instead of creating an inline link that matches the format of the other links in the same menu, it instead looks like it is being recognized as a
instead and ends up not having the same format as the rest of the links in the same drop down menu.
Depending on your metafield type, metafield_tag will produce different kinds of HTML tag/element, so I believe using it like you do actually breaks HTML structure.
You should be able to see it if you “view page source” (which shows you exact HTML) rather then “inspect element” which shows you browsers interpretation of your HTML code (including browsers attempts to fix HTML errors).
If it’s a page reference type metafield, you should rather use
It is funny, because using the code that you provided, it does properly end up allowing the “Wholesale order form” to be correctly formatted with the rest of the menu. However, when I use value.url at the end, it doesn’t do anything other than kind of like refreshing the page that you were currently already on.
This is what the line of code looks like when I click to view source on the site
Wholesale Order Form
If I end up using the .value code, this is what my url ends up having at the end, which I guess is saying Liquid error (sections/Liquid) error sections/header line 288, metafield tag can only be used with a metafield drop.
As expected, my code does not break HTML structure.
And you obviously can’t do {{ customer.metafields.custom.wholesale_order_form.value | metafield_tag }} because metafield_tag expects metafield and not it’s value.
Since value.url does not produce anything, the question is how your metafield is defined? Can you share a screenshot showing the metafield type?
What I actually need right now is something similar to this screenshot of my metafield definition, where we can see that the type is “Page” and it’s “One page”, not a “List”:
– by default, if I am not mistaken, richtext is either wrapped with
, or is a list of paragraphs.
Richtext is ok if you want to simply output some HTML-formatted text on your page but not in your use case.
You may try href=“{{ metafield.value | strip_html | strip }}”, but ideally –
– I would suggest you to remove and re-define the metafield.
If you’re ready to type in/copy-paste the URL manually, then use “Single line text” and use href=“{{ metafield.value }}” (not recommended, because may have incidental spaces or some typos).
I’d rather recommend to either use URL metafield type and same code. URL would be easier to enter and adds some validation. Will allow links to other sites if your form is located not on your site.
Or, use the Reference: Page type (probably the best, but only allows Page objects in your store, not good if need to link to 3rd party service) and then use value.url as I suggested initially.
it also depends on how you enter your metafield data – whether you simply type-in/copy-paste the URL or use the “insert link” button in rich text editor. too many variables, that’s why re-defining the metafield as URL will be the best option in the long run.
This is how I have it under the customer’s metafields.
I am close to just simply leaving it as is, since it seems too difficult for me to figure out. If I could get away with simply pushing the text over using padding or something similar, then I would be ok with that as well. It’s not really a major/critical part of my site, but it would be nice if I could figure something out at least.
Thanks. I’ll give it a closer look/try tomorrow. Just quickly testing it out right now seems like it doesn’t work. Nothing shows up in the drop down menu after adding this in.