[英]How to use wordpress function wp_enqueue_script() in php?
I have a php function as shown below.我有一个 php 函数,如下所示。 The following function is being used at many places.
以下功能正在许多地方使用。
function render_brightcove_player($active_feed, $poster_image = false)
{
$poster = '';
if ($poster_image) {
$poster = 'poster=' . esc_url($poster_image);
}
?>
<div class="hsc-video" onclick="hscLogo()">
<div class="hsc-video__inner">
<script src="//players.brightcove.net/1242843915001/SJ3Tc5kb_default/index.min.js"></script>
</div>
</div>
<?php
wp_enqueue_script(
'miscellaneous-scripts',
HSC_TEMPLATE_URL . "/assets/js/miscellaneous.js"
);
}
In the php code, I have added wordpress function wp_enqueue_script()
.在 php 代码中,我添加了 wordpress 函数
wp_enqueue_script()
。 Inside miscellaneous.js file I am using:在我使用的 miscellaneous.js 文件中:
function hscLogo() {
document.getElementsByClassName("hsc-tv-logo")[0].style.display = "none";
}
I am wondering if that is the right way to use wp_enqueue_script()
function in php.我想知道这是否是在 php 中使用
wp_enqueue_script()
函数的正确方法。 Do I need to place wp_enqueue_script() somewhere else ?我需要将wp_enqueue_script()放在其他地方吗?
This is the first time I am using wp_enqueue_script
in wordpress.这是我第一次在 wordpress 中使用
wp_enqueue_script
。 Here is the tree structure of javascript folders/files.这是 javascript 文件夹/文件的树结构。
Is your php code in wordpress?你的 php 代码是在 wordpress 中吗? And if it is called by any wordpress template or plugin, you can use wp_enqueue_script in your php file.
如果它被任何 wordpress 模板或插件调用,你可以在你的 php 文件中使用 wp_enqueue_script。 You can check the following link to study wp_enqueue_script.
您可以查看以下链接来学习 wp_enqueue_script。 https://developer.wordpress.org/reference/functions/wp_enqueue_script/
https://developer.wordpress.org/reference/functions/wp_enqueue_script/
wp_enqueue_script(
'miscellaneous-scripts',
HSC_TEMPLATE_URL . "/assets/js/miscellaneous.js",
array(),
'1.0.0', //Version
true // Load in footer.
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.