Modify link for language change [SOLVED]

Hey @Edward

Ok I made some modifications, the code will add an “Onclick” to the image. So you don’t need to use the interaction option to make the image a link. And it will also turn the curser into a pointer.

Example Project

Blocs_Add_Language_Suffix_To_URL_Image_Link.bloc (719.5 KB)

Step 1

Add the following class to the image
.btn-lang

Step 2

Add the following custom attribute to the image (change the value for the language)
data-language="en"

Step 3

Copy this code to your page footer
<script>
var currentURL = window.location.href;
var sliceURL = currentURL.substring(0, currentURL.length - 5);

document.querySelectorAll('.btn-lang').forEach(function(button) {
 	var newLang = (button.getAttribute("data-language"));
 	button.style.cursor = 'pointer'; 
 	(button.setAttribute("onclick", "location.href = '" + sliceURL + "-" + newLang + ".html';"));
});
</script>

Step 4

Make any adjustments needed to suit your site.
1 Like