Forked from benjaminsehl/headless-theme-redirect.liquid
Created
May 23, 2023 15:10
-
-
Save juanpprieto/83b7fca57bc4209a9292a9f044f14b10 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 hidden or 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