footer script disable on a single page



  • Hello.

    I have received a working script from my helpdesk software, but I don't want this script to run on one specific page in Wordpress.

    This page has ID 920.

    How can I get the script below to run normally, except on the page with ID 920?

    I would love to hear from you.

    <script type="text/javascript">
    window.Trengo = window.Trengo || {};
    window.Trengo.key = 'xxxxxxxxxxxxxxxxxxx';
    (function(d, script, t) {
    script = d.createElement('script');
    script.type = 'text/javascript';
    script.async = true;
    script.src = 'https://xxxx.xxxxxx.xxxxxx/embed.js';
    d.getElementsByTagName('head')[0].appendChild(script);
    }(document));

    window.addEventListener('keydown', function(e) {
    if(e.keyCode == 32 && e.target == document.body) {
    e.preventDefault();
    }
    });
    </script>



  • Hello,

    Unfortunately there is not an easy way to do that with the plugin. But you may use your theme's functions.php file to insert the code using simple if else statement.

    HTH



  • Can you help me with that if/else statement?



  • It could be something like this:

    function anand657_hook_javascript() {
      if (!is_page ('920')) { 
        ?>
            <script type="text/javascript">
              // your javscript code goes here
            </script>
        <?php
      }
    }
    add_action('wp_footer', 'anand657_hook_javascript');
    

    PS: DON'T RUN THE ABOVE CODE ON LIVE SITE UNLESS YOU HAVE A BACKUP. it might break your site if any thing goes wrong. It's good to have backup handy.


Log in to reply