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 4 replies, has 2 voices.

Last updated by maxL-15 1 month, 2 weeks ago.

Assigned support staff: Riffaz.

Author Posts
September 1, 2019 at 2:26 pm #4492643

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:43 pm #4492885

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:

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.

Let me know how it goes.

Regards,
Riffaz.

September 1, 2019 at 4:59 pm #4492899

maxL-15

So I just added the code and clicked save and now the site is down..

September 1, 2019 at 5:32 pm #4492915

Riffaz
Supporter

Languages: English (English )

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

Hi,

As I explained you already "Set and adjust your code according to this format "
It's where it goes out of the support scope.

ex:
1.
if you have already PHP code and the tag is opened you have to remove

<?php

from the code I gave you.

2. you have replace this line with your tawk code:

 <!---your code to spanish--->

did you remove and replace it

3. if you have only two languages you have to remove extra

elseif

did you do that?
If you are not familiar with PHP this will be a headache.
In that case, you can consider: https://wpml.org/contractors/

Let me know.

Regards,

September 3, 2019 at 3:01 pm #4505637

maxL-15

My issue is resolved now. Thank you!