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 danielK-15 2 months, 3 weeks ago.

Assigned support staff: Rohan Sadanandan.

Author Posts
July 26, 2019 at 10:56 am #4289253

danielK-15

i need to add a script for a chat window (tawk.to) ... i need 5 different scripts.. .for each language one ... for example for mykey.shop/it the script which show the italian chat window and so on...

July 26, 2019 at 12:20 pm #4289601

Rohan Sadanandan
Supporter

Languages: English (English )

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

Hello,

Thank you for contacting WPML Support.

You can use the wpml_current_language hook to get the current language code.

$my_current_lang = apply_filters( 'wpml_current_language', NULL );

Based on the language code you can then write the condition for the script.

For more details you can read this documentation:
https://wpml.org/wpml-hook/wpml_current_language/

If you have any doubts, please let me know.

Thanks,
Rohan

July 26, 2019 at 12:46 pm #4289685

danielK-15

hmm i not that experiemced... can you help me a little bit more...

i need to put this code in the head for the german langauge...

<!--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-->

where do i put it and how do i have to use the hooks?

thanks so much

July 26, 2019 at 2:14 pm #4290105

Rohan Sadanandan
Supporter

Languages: English (English )

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

Hello,

Please check the below sample code:

<?php
$current_language_code = apply_filters( 'wpml_current_language', null );
if($current_language_code == '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='<em><u>hidden link</u></em>';
s1.charset='UTF-8';
s1.setAttribute('crossorigin','*');
s0.parentNode.insertBefore(s1,s0);
})();
</script>
<!--End of Tawk.to Script-->
 
<?php
elseif($current_language_code == 'fr'):
?>
<script>
// javascript code for French
</script>
 
<?php
elseif($current_language_code == 'nl'):
?>
 
<script>
// javascript code for Dutch
</script>
<?php
endif;
?>

You can put this code in the header/footer according to your needs.
I have added your javascript & added 2 more extra conditions for other languages also.

I hope you can understand this code.

Thanks,
Rohan

July 26, 2019 at 3:19 pm #4290383

danielK-15

My issue is resolved now. Thank you!