Agê*_*ber 4 javascript wordpress wordpress-theming custom-wordpress-pages wordpress-admin
我需要在所有 WordPress 管理页面(后端)上添加 Livechat 小部件。
Livechat JavaScript 代码是这样的:
<!-- Start of LiveChat (www.livechatinc.com) code -->
<script type="text/javascript">
window.__lc = window.__lc || {};
window.__lc.license = 12345678;
(function() {
var lc = document.createElement('script'); lc.type = 'text/javascript'; lc.async = true;
lc.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cdn.livechatinc.com/tracking.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(lc, s);
})();
</script>
<noscript>
<a href="https://www.livechatinc.com/chat-with/10437202/" rel="nofollow">Chat with us</a>,
powered by <a href="https://www.livechatinc.com/?welcome" rel="noopener nofollow" target="_blank">LiveChat</a>
</noscript>
<!-- End of LiveChat code -->
Run Code Online (Sandbox Code Playgroud)
Livechat 有一个可以在前端页面上进行聊天的插件。我实际上想将此代码添加到 WordPress 后端的每个页面。
我正在考虑通过functions.php我的子主题将其放在管理页脚中,但我不确定如何将此代码放在一起。
我插入子主题的代码是这样的:
function remove_footer_admin () {
echo 'My footer text. Thank you WordPress for giving me this filter.';
}
add_filter( 'admin_footer_text', 'remove_footer_admin' );
Run Code Online (Sandbox Code Playgroud)
我应该把这段代码放在哪里工作?
Kas*_*que 12
您可以使用 hook 在管理页脚中添加 JavaScript 代码admin_footer。
如果你还需要在前端添加相同的代码,那么wp_footer也应用钩子。
这是子主题的functions.php中的完整代码:
// Function to render LiveChat JS code
function lh_add_livechat_js_code() {
?>
<!-- Start of LiveChat (www.livechatinc.com) code -->
<script type="text/javascript">
window.__lc = window.__lc || {};
window.__lc.license = YOUR_KEY; // use your license key here
(function() {
var lc = document.createElement('script'); lc.type = 'text/javascript'; lc.async = true;
lc.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cdn.livechatinc.com/tracking.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(lc, s);
})();
</script>
<noscript>
<a href="https://www.livechatinc.com/chat-with/10437202/" rel="nofollow">Chat with us</a>,
powered by <a href="https://www.livechatinc.com/?welcome" rel="noopener nofollow" target="_blank">LiveChat</a>
</noscript>
<!-- End of LiveChat code -->
<?php
}
add_action( 'admin_footer', 'lh_add_livechat_js_code' ); // For back-end
add_action( 'wp_footer', 'lh_add_livechat_js_code' ); // For front-end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10789 次 |
| 最近记录: |