0

I'm new to Wordpress, have tried to put the chat bubble JS script into specific pages. Though I've found few answers, but still can't fully understand how it works.

When I tried to put the code below in the theme function.php.The chat bubble doesn't show up at all.

I wonder there's some error in the code.

Thanks in advance if someone can help me out with this!

Here's my website https://staymeander.com/en/meander1948-en/

function wpb_hook_javascript_footer() {
    if(is_page( array('3854','253') ) ) {
    ?>
        <script type="text/javascript">
    (function () {
        var options = {
            line: "//lin.ee/gl1UqsC", // Line QR code URL
            call: "+886225588812", // Call phone number
            call_to_action: "Message us", // Call to action
            button_color: "#FF6550", // Color of button
            position: "right", // Position may be 'right' or 'left'
            order: "line,call", // Order of buttons
        };
        var proto = document.location.protocol, host = "getbutton.io", url = proto + "//static." + host;
        var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = url + '/widget-send-button/js/init.js';
        s.onload = function () { WhWidgetSendButton.init(host, proto, options); };
        var x = document.getElementsByTagName('script')[0]; x.parentNode.insertBefore(s, x);
    }   
})();
</script>
    <?php
    }
}
add_action('wp_footer', 'wpb_hook_javascript_footer');
0

If you're using IDs for is_page() you should pass them as integers, not strings. Otherwise WordPress is looking for pages with a slug of "3854", not a page with that ID.

So instead of:

if ( is_page( array( '3854', '253' ) ) ) {}

Use:

if ( is_page( array( 3854, 253 ) ) ) {}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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