Last active
October 15, 2021 23:38
-
-
Save freakdesign/95b6d4f02bd7b4f4a1ba to your computer and use it in GitHub Desktop.
Detect if an admin is logged into Shopify using liquid.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
Simple method for detecting an Admin in Shopify using liquid. | |
Quick code by jason at freakdesign.com.au | |
Related Blog post: http://freakdesign.com.au/blogs/news/34154561 | |
--> | |
{% capture CFH %}{{ content_for_header }}{% endcapture %}{{ CFH }} | |
{% if CFH contains 'admin_bar_iframe' %} | |
{% assign isAdmin = true %} | |
{% endif %} |
if CFH contains 'adminBar' or CFH contains 'previewBar'
assign isAdmin = true
endif
shopify uses:
adminBarInjector
when you are viewing the live theme
previewBarInjector
when you are previewing a non-live theme
this whole snippet will trigger a Shopify theme-check linter ContentForHeaderModification
error but I'm choosing to ignore it
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just used
preview_bar_injector
and it's working correctly for me.