通过wp_enqueue_scripts添加js文件时,它将其放在html源代码的<head>
标记中。
但是在DOM(F12)中,它被放置在<body>
中。
可能是什么原因?
这是我的页面
<!DOCTYPE html>
<html>
<head>
<title>PAGE</title>
<link rel="stylesheet" id="query-monitor-css" href="https://www.sukkah2go.kipa.co.il/wp-content/plugins/query-monitor/assets/query-monitor.css?ver=1478770264" type="text/css" media="all" />
<link rel="stylesheet" id="font-awesome-css" href="https://www.sukkah2go.kipa.co.il/wp-content/plugins/wipi-builder/css/font-awesome.min.css?ver=4.6.3" type="text/css" media="all" />
<link rel="stylesheet" id="mono-social-icons-css" href="https://www.sukkah2go.kipa.co.il/wp-content/themes/wipi/css/mono-social-icons.css?ver=1.2.1" type="text/css" media="all" />
<link rel="stylesheet" id="hebrew-fonts-css" href="https://www.sukkah2go.kipa.co.il/wp-content/themes/wipi/css/hebrew-fonts.css?ver=1.2.1" type="text/css" media="all" />
<link rel="stylesheet" id="jquery-magnificpopup-css" href="https://www.sukkah2go.kipa.co.il/wp-content/plugins/wipi-builder/css/jquery.magnificpopup.css?ver=1.2.1" type="text/css" media="all" />
<link rel="stylesheet" id="wipi-css" href="https://www.sukkah2go.kipa.co.il/wp-content/uploads/wipi/skin-57f534186c4d2.css?ver=4.6.1" type="text/css" media="all" />
<link rel="stylesheet" id="wipi-rtl-css" href="https://www.sukkah2go.kipa.co.il/wp-content/themes/wipi/css/rtl.css?ver=4.6.1" type="text/css" media="all" />
</head>
<body>
</body>
</html>
答案 0 :(得分:1)
看看代码参考: https://developer.wordpress.org/reference/functions/wp_enqueue_script/
正如你所看到的,布尔类型的最后一个参数,如果设置为true,它将在文档正文中输出脚本文件,而不是在头文件中。也许那就是问题。
wp_enqueue_script( string $handle, string $src = false, array $deps = array(), string|bool|null $ver = false, bool $in_footer = false )