Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jongacnik
Last active August 4, 2020 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jongacnik/cc339f2b36b88cc87cd8a09985bc87ea to your computer and use it in GitHub Desktop.
Save jongacnik/cc339f2b36b88cc87cd8a09985bc87ea to your computer and use it in GitHub Desktop.
Shopify Homepage Redirect

Shopify Homepage Redirect

Use the "Custom Content" section in a debut theme to add a code block with the contents of shopify-redirect.js. This will allow you to create a user-editable redirect. The code is wrapped in an iFrame check so the redirect is not triggered while in the editor. Editors can toggle the redirect on/off by showing/hiding that section.

<script>
function inIframe () {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}
if (!inIframe()) {
window.location.replace('/collections/all')
} else {
if (document.currentScript) {
var script = document.currentScript
script.parentNode.innerHTML = '<p>This page redirects to <code>/collections/all</code>. To disable the redirect, hide the "Custom Content" section.</p>'
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment