Skip to content

Instantly share code, notes, and snippets.

@benjaminsehl
Last active May 24, 2023 09:25
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save benjaminsehl/cdd0ce53951659db1266276cda854285 to your computer and use it in GitHub Desktop.
Save benjaminsehl/cdd0ce53951659db1266276cda854285 to your computer and use it in GitHub Desktop.
Shopify Headless Theme.liquid Redirect — UPDATE: replace with this theme: https://github.com/benjaminsehl/shopify-headless-theme
{% comment %}
UPDATE: Now you can use this theme to more easily manage your redirects:
https://github.com/benjaminsehl/shopify-headless-theme
{% endcomment %}
{% assign new_website = 'https://headless-website.com/' %}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="robots" content="noindex">
<link rel="preconnect" href="{{new_website}}" crossorigin>
<script>
var discount_code = getCookie('discount_code');
function getCookie(name) {
name = name + '=';
var decodedCookie = decodeURIComponent(document.cookie);
var cookies = decodedCookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].trim();
if (cookie.indexOf(name) == 0) {
return cookie.substring(name.length, cookie.length);
}
}
}
var url = window.location;
var baseUrl =
url.protocol + '//' + url.host + '/' + url.pathname.split('/')[0];
var newUrl =
'{{new_website}}';
url = url.toString();
url = url.replace(baseUrl, newUrl);
if (url.includes('?') && discount_code) {
url = url + '&discount=' + discount_code;
} else if (discount_code) {
url = url + '?discount=' + discount_code;
}
window.location.replace(url);
</script>
<!-- {{content_for_header}} -->
</head>
<body>
{{content_for_layout}}
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment