I am trying to add HTML widgets (different ones) for the different languages. It is for the Tawk.to chat-widget.
This is the code for NL
<!--Start of Tawk.to Script-->
<script type="text/javascript">
var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
(function(){
var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
s1.async=true;
s1.src='hidden link';
s1.charset='UTF-8';
s1.setAttribute('crossorigin','*');
s0.parentNode.insertBefore(s1,s0);
})();
</script>
<!--End of Tawk.to Script-->
This is the code for DE
<!--Start of Tawk.to Script-->
<script type="text/javascript">
var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
(function(){
var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
s1.async=true;
s1.src='hidden link';
s1.charset='UTF-8';
s1.setAttribute('crossorigin','*');
s0.parentNode.insertBefore(s1,s0);
})();
</script>
<!--End of Tawk.to Script-->
I found some PHP stuff on the forum of WPML to add custom code for each language but it wasn't working.
We do not provide code in support which is out of the support scope.
Anyhow, the following solution solved another users with the same issue:
You did not mention what code you are using or where you are using it.
Typically in WordPress you have to follow this format to use different code for different languages.
<?php
add_action( 'wp_head', 'my_custom_js' );
function my_custom_js() {
if(ICL_LANGUAGE_CODE=='en'){?>
<!--- your code to english--->
<?php } elseif(ICL_LANGUAGE_CODE=='de'){?>
<!---your code to german--->
<?php
} elseif(ICL_LANGUAGE_CODE=='fr'){?>
<!---your code to french----->
<?php
} elseif(ICL_LANGUAGE_CODE=='es'){?>
<!---your code to spanish--->
<?php
}
}
Set and adjust your code according to this format and add this code to your functions.php
It will work.