1

I would like to add tawk.to widget script just before the body tag. I would like to add the code to the functions.php file of my child theme. How can I do this? A code sample will assist a long way. The following is my code:

    <!--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='https://embed.tawk.to/5b54359ee21878736ba23110/default';
s1.charset='UTF-8';
s1.setAttribute('crossorigin','*');
s0.parentNode.insertBefore(s1,s0);
})();
</script>
<!--End of Tawk.to Script-->

1 Answer 1

2

You can the code to head or before body tag this way. Add this code at the last of functions.php

add_action( 'wp_head', function() {
    ?>
    <!--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='https://embed.tawk.to/5b54359ee21878736ba23110/default'; s1.charset='UTF-8'; s1.setAttribute('crossorigin','*'); s0.parentNode.insertBefore(s1,s0); })();
    </script>
    <?php
} );

Hope it helps

2
  • Thank you. It worked.
    – 3vanse
    Dec 6, 2020 at 14:52
  • if it helped. please upvote or accept the answer by clicking that tick icon. It would really help me. Dec 6, 2020 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.