问题描述
我正在为 WordPress 创建一个插件,当我在插件主文件中使用以下代码时,它会在 <head>
中加载 js,它工作正常。
wp_enqueue_script ( 'custom-script','https://cdnjs.cloudflare.com/ajax/libs/bootstrap-v4- rtl/4.6.0-1/js/bootstrap.bundle.min.jsf');
但是当我在函数中使用它时(例如 show_form()
):
function show_form()
{
wp_enqueue_script ( 'custom-script','https://cdnjs.cloudflare.com/ajax/libs/bootstrap-v4- rtl/4.6.0-1/js/bootstrap.bundle.min.js');
require_once 'form.php';
}
它在页面底部加载脚本(在 </body>
之前)。
我的代码有什么问题?
仅当我的 form.php 加载时,我才需要将脚本放入 <head>
中。
我知道我可以直接在 form.php 中加载脚本,但我需要通过 wp_enqueue_script 加载脚本
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)