creative designer

Whilst there isn't an isAdmin variable available in Liquid it doesn't mean you can't replicate something similar. Long story short, it's possible to detect if the admin is logged in using liquid alone. No JavaScript or customer accounts required.

The method for detection is quite simple. When logged in you'll see that your site will display a nifty admin bar. The code that Shopify adds to create that bar is what gives us the clues we need to determine if the admin is logged in or not.

Every theme contains this:

{{ content_for_header }}

If you look in the source html of the page where that section is you'll see a bunch of JavaScript code. The important line is this:

var element = document.getElementById("admin_bar_iframe");

See something that might be telling us we're an admin? Now that we know this line exists we just need to search content_for_header for the admin_bar_iframe string. If it exists, we're an admin. See a basic example below:


Like to work with me?

Let's talk