使用add_action
将函数添加到wp_footer
钩子,然后在函数内部,您可以在输出脚本之前检查您是否在特定页面上。
例如,上的帮助Scout脚本/contact-us/
页码:
add_action(\'wp_footer\', \'maybe_add_javascript\');
function maybe_add_javascript() {
if (!is_page(\'contact-us\')) {return;}
?>
<script type="text/javascript">!function(e,t,n){function a(){var e=t.getElementsByTagName("script")[0],n=t.createElement("script");n.type="text/javascript",n.async=!0,n.src="https://beacon-v2.helpscout.net",e.parentNode.insertBefore(n,e)}if(e.Beacon=n=function(t,n,a){e.Beacon.readyQueue.push({method:t,options:n,data:a})},n.readyQueue=[],"complete"===t.readyState)return a();e.attachEvent?e.attachEvent("onload",a):e.addEventListener("load",a,!1)}(window,document,window.Beacon||function(){});</script>
<script type="text/javascript">window.Beacon(\'init\', \'602b66a1-948e-493f-b0dd-c2828b2eb860\')</script>
<?php
}