I'm trying to insert a block on our mobile homepage with shortcut links to our 4 most popular categories (through an A/B testing platform). Our website operates in different countries, so the links to the categories are different depending on which country the user is visiting the Homepage on, and our website does not have automatic redirects in place.
For example:
If they are currently on https://www.brand.com/uk-en/, it should link to https://www.brand.com/uk-en/category1.html
But
If they are on https://www.brand.com/fr-fr/, it should link to https://www.brand.com/fr-fr/category1.html
<div class="shortcuts-block">
<div class="row-1"><a href="https://www.brand.com/uk-en/category1.html">Links to category 1</a></div>
<div class="row-2"><a href="https://www.brand.com/uk-en/category2.html">Links to category 2</a></div>
<div class="row-3"><a href="https://www.brand.com/uk-en/category3.html">Links to category 3</a></div>
<div class="row-4"><a href="https://www.brand.com/uk-en/category4.html">Links to category 4</a></div>
</div>
I'm not familiar with JS, so was hoping if someone could help me with how to achieve this? I found this script which looks close to what I need, but I don't think that's quite it. I need it to match the /uk-en/ part of the target URL with whatever is in the current URL. I hope that makes sense. There are 13 different possibilities for the country/language string.
<script>
$(document).ready(function(){
$('a[href^="http://"]').each(function(){
var oldUrl = $(this).attr("href"); // Get current url
var newUrl = oldUrl.replace("http://", "https://"); // Create new url
$(this).attr("href", newUrl); // Set herf value
});
});
</script>