• Resolved digidestination

    (@digidestination)


    Hi, I would like to include chat popup on my website backend only and so far I have difficulty doing that, can someone explain how I should amend this 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/[CHATIDCODE]/default';
    s1.charset='UTF-8';
    s1.setAttribute('crossorigin','*');
    s0.parentNode.insertBefore(s1,s0);
    })();
    </script>
    <!--End of Tawk.to Script-->

    At this moment when I try to strip

    <!--Start of Tawk.to Script-->
    <script type="text/javascript">

    and

    </script>
    <!--End of Tawk.to Script-->

    I’m getting error: “The snippet has been deactivated due to an error on line 1:
    syntax error, unexpected ‘var’ (T_VAR)”

    I would really appreciate if someone could help me.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    The issue here is that you’re trying to use a HTML/JavaScript snippet, when this plugin only supports activating PHP snippets that work like plugins do. In order to use your code, you’ll need to wrap it in an action filter hook, like so:

    add_action( 'wp_footer', 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/[CHATIDCODE]/default';
    s1.charset='UTF-8';
    s1.setAttribute('crossorigin','*');
    s0.parentNode.insertBefore(s1,s0);
    })();
    </script>
    <!--End of Tawk.to Script-->
    
    <?php } ); ?>

    This will load the script on the front-end of your website, down the bottom of the HTML code.

    Thread Starter digidestination

    (@digidestination)

    Hi thank you for your reply,
    I would like to load it only at the back-end of my site.

    I also tried loading provided by you code on my site in snippets and it didn’t load:

    This is the settings that I'm adding

    Plugin Author Shea Bunge

    (@bungeshea)

    The code I gave you was for loading the script on the front-end of the site only. Here’s a different snippet which will only load the code on the back-end, in the administration dashboard:

    add_action( 'admin_print_footer_scripts', 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/[CHATIDCODE]/default';
    s1.charset='UTF-8';
    s1.setAttribute('crossorigin','*');
    s0.parentNode.insertBefore(s1,s0);
    })();
    </script>
    <!--End of Tawk.to Script-->
    
    <?php } ); ?>
    Thread Starter digidestination

    (@digidestination)

    Thank you,
    That worked!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Tawk.to backend snippet’ is closed to new replies.