php – How to add JS script in specific pages in WordPress?

Question

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
Leo Cheng 2 weeks 2021-09-07T21:58:58-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse