我正在嘗試將JavaScript插入到WordPress頁面。我說這的functions.php:當我嘗試保存它時,wordpress網站頁面上的Javascript消失
function add_custom_code() {
if (is_front_page()) { ? >
<script>
(function() {
var randomId = Math.floor(Math.random() * 100000);
var targetElemId = ‘bcom_rwidget_’ + randomId;
document.write(‘ < div id = 」‘+targetElemId + ‘」 > < /div>‘);
var script = document.createElement(‘script’);
script.type = ‘text/javascript’;
script.async = true;
script.src = ‘http: //www.booking.com/review_widget/gb/the-manor-house-bed-amp-breakfast-enter code here`trunch.en.html?tmpl=review_widget/review_widget&wid=’ + targetElemId + ‘&wtype=box_small&hotel_id=XXXXX&`enter code here`widget_language=en’;
var node = document.getElementsByTagName(‘script’)[0];
node.parentNode.insertBefore(script, node);
}()); < /script> < ? php
}
}
add_action('wp_footer', 'add_custom_code');
但是當我添加腳本的頁面,它只要我 試圖挽救它消失。
如何在WordPress頁面上運行安全JavaScript?