[英]How to add Javascript after closing /body tag in WordPress
我想在幾個WordPress頁面中嵌入一個iFrame。 每個頁面都將使用不同的iFrame內容。 這適用於商業網站,因此需要第一個iframe作為客戶的登錄信息。 不同WP頁面上的后續iframe將用於產品搜索,結帳...((我的問題在底部))
在header.php中,我放置了一些初始代碼,我需要將其包含在每個WordPress頁面中。
我在每個頁面的主體中添加了iframe。
我需要將iframe初始化為特定的iframe內容。 我想在結束</body>
標簽之后放置此代碼,如下所示:
<html>
<head>
<script>
var absDomain = "http://www.webstore.com/"
var iframeObj;
var timestampString = '' + new Date().getTime() + ''
document.write('<script type="text/javascript" src="' + absDomain + 'Support.js?'+timestampString+'"><\/script>');
document.write('<script type="text/javascript" src="' + absDomain + 'ProductSearch.js?'+timestampString+'"><\/script>');
document.write('<script type="text/javascript" src="' + absDomain + 'Environment.js?'+timestampString+'"><\/script>');
function gotoIframe(theLocation){
var timeStamp = "";
iframeObj = document.getElementById("iframeContent");
timeStamp = "&" + new Date().getTime();
iframeObj.src = absDomain + theLocation + "?iframe=yes" + timeStamp;
}
function executeIFrameProductSearch(str1, str2){
goTo_CategoryForIframe(str1, str2, document.getElementById("iframeContent"));
}
</script>
</head>
<body>
<!-- iFrame embedded below -->
<iframe id="iframeContent" style="width:100%;height:500px; " src=""></iframe>
</body>
<script>
//script needed for initial iframe page and iframe support.
iframeObj = document.getElementById("iframeContent");
gotoIframe("CustomerLogin.html");
</script>
</html>
//After the above code section (after the </body> tag) is embedded into the Login page, I expect to use:
//Customer Login:
<a href="javascript:gotoIframe('CustomerLogin.html')">Customer Login</a>
//Product Search:
<a href="javascript:gotoIframe('ProductSearch.html')">Product Search</a>
問題:在哪里插入每個特定WordPress頁面的結束標記之后的代碼? 謝謝。
在腳本標記之后放置腳本標記是無效的,但如果你真的想這樣做,你可以查看主題的footer.php。
例如,您可以在footer.php中找到這樣的代碼:
<?php
</div><!-- close tag for content container -->
?>
<footer>
<!-- footer content -->
</footer>
</body>
<!-- here is the place to put your code -->
</html>
將此函數復制並粘貼到functions.php文件中
//alert(); enable alert to test
//script needed for initial iframe page and iframe support.`function your_function() {
echo '<script>`
iframeObj = document.getElementById("iframeContent");
gotoIframe("CustomerLogin.html");
</script>';
}
add_action('wp_footer','your_function',100); //這將在每個頁面的body標簽之后添加腳本
其他選項將//你的其余功能.php在這一行或任何地方!
function yourprefix_scripts_after_opening_body_tag(){$ javascript = file_get_contents(get_template_directory()。'/ js / opening-body.js'); 回聲''。 $ javascript。 ''; }
add_action('yourprefix_after_opening_body_tag','yourprefix_scripts_after_opening_body_tag');
將此代碼粘貼到您要顯示的footer.php中
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.