Last active
November 11, 2024 20:47
-
-
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
This file contains 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
{% 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