admin管理员组

文章数量:1122832

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 /

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');

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');
Share Improve this question asked Sep 8, 2021 at 2:58 Leo ChengLeo Cheng 1
Add a comment  | 

1 Answer 1

Reset to default 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 ) ) ) {}

本文标签: phpHow to add JS script in specific pages in Wordpress