This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 2 replies, has 2 voices.

Last updated by maxL-15 1 month, 1 week ago.

Assigned support staff: Riffaz.

Author Posts
September 1, 2019 at 4:35 pm #4492869

maxL-15

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.

Thanks in advance!

September 1, 2019 at 4:42 pm #4492879

Riffaz
Supporter

Languages: English (English )

Timezone: Asia/Colombo (GMT+05:30)

Hi,

Thank you for contacting WPML support.

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:

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.

Let me know how it goes.

Regards,
Riffaz.

September 3, 2019 at 3:01 pm #4505649

maxL-15

My issue is resolved now. Thank you!