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
1 Answer
Reset to default 0If 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
版权声明:本文标题:php - How to add JS script in specific pages in Wordpress? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736294154a1929296.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论