Skip to content

Instantly share code, notes, and snippets.

@freakdesign
Last active October 15, 2021 23:38
Show Gist options
  • Save freakdesign/95b6d4f02bd7b4f4a1ba to your computer and use it in GitHub Desktop.
Save freakdesign/95b6d4f02bd7b4f4a1ba to your computer and use it in GitHub Desktop.
Detect if an admin is logged into Shopify using liquid.
<!--
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 %}
@eballeste
Copy link

eballeste commented Oct 15, 2021

  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