Hide the chat widget on a WordPress page

To hide the chat widget on some pages of your WordPress website, do the following:

Step #1

Install a plugin that allows you to add custom codes to footer. For example, you can use this one: Head and Footer Scripts Inserter.

Step #2

Add this code to the footer of your website:

<script>
    (function() {
        var hideOnPages = [
            'www.your-domain-name.com/hide-page-1/',
            'hide-page-2'
        ];

        // don't modify code below unless you know what you are doing
        var style;
        var head = document.head || document.getElementsByTagName('head')[0];

        addForceHideChaport();
        showOrRemoveChaport(true);

        function addForceHideChaport() {
            // add css to hide the chaport container
            var css = '.chaport-container { opacity: 0 !important; }';
            head = document.head || document.getElementsByTagName('head')[0];
            style = document.createElement('style');

            head.appendChild(style);

            style.type = 'text/css';
            style.appendChild(document.createTextNode(css));
        }

        function removeForceHideChaport() {
            if (style) {
                head.removeChild(style);
                style = null;
            }
        }

        function showOrRemoveChaport(allowOneTimeout) {
            if (!window.chaport) {
                if (allowOneTimeout) {
                    setTimeout(showOrRemoveChaport, 100);
                }
            } else {
                if (isPageOneOf(window.location.href, hideOnPages)) {
                    window.chaport.on('ready', function () {
                        window.chaport.stopSession();
                    });
                } else {
                    removeForceHideChaport();
                }
            }
        }

        function isPageOneOf(url, patterns) {
            for (var i = 0, len = patterns.length; i < len; i++) {
                if (typeof patterns[i] === 'string') { // look for substring match
                    if (url.indexOf(patterns[i]) !== -1) return true;
                } else if (typeof patterns[i].test === 'function') { // presume regex
                    if (patterns[i].test(url)) return true;
                }
            }

            return false;
        }
    })();
</script>

In this part of the code:

<script>
    (function() {
        var hideOnPages = [
            'www.your-domain-name.com/hide-page-1/',
            'hide-page-2'
        ];

don't forget to change 'www.your-domain-name.com/hide-page-1/', 'hide-page-2' to the URL or a part of the URL of a page/pages where you want to hide the chat widget.

Please note: This code is a part of JavaScript API that is available only in the PRO plan.

results for ""

    No results matching ""