Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 未调用wp_排队_脚本_Php_Wordpress - Fatal编程技术网

Php 未调用wp_排队_脚本

Php 未调用wp_排队_脚本,php,wordpress,Php,Wordpress,我在StackOverflow和其他网站上看到了很多关于为什么“wp_enqueue_脚本”不起作用的问题,但这些都不是我想要的 我想导入一个脚本到我的Wordpress主题,我复制了一个从主要开发者Wordpress网站剪下的代码 我的'functions.php'中有以下代码,输出为'output 1OUTPUT 4'。 “wpdocs\u theme\u name\u scripts()”似乎从未得到调用 /** * Proper way to enqueue scripts and s

我在StackOverflow和其他网站上看到了很多关于为什么“wp_enqueue_脚本”不起作用的问题,但这些都不是我想要的

我想导入一个脚本到我的Wordpress主题,我复制了一个从主要开发者Wordpress网站剪下的代码

我的'functions.php'中有以下代码,输出为'output 1OUTPUT 4'。 “wpdocs\u theme\u name\u scripts()”似乎从未得到调用

/**
 * Proper way to enqueue scripts and styles.
 */
function wpdocs_theme_name_scripts() {
    echo "OUTPUT 2";
    wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/main.js', array(), '1.0.0', true );
    echo "OUTPUT 3";
}
echo "OUTPUT 1";
add_action( 'wp_enqueue_scripts', 'wpdocs_theme_name_scripts' );
echo "OUTPUT 4";

在header.php中使用wp_head()函数

请注意,
wpdocs\u theme\u name\u scripts()
将不会在
echo“OUTPUT 1”之后调用和前
回显“输出4”

add\u action()
只会注册一个回调,当遇到
wp\u head()
时会运行该回调。你可以在中找到更多的细节

您是否在主题中添加了
wp\u head()
?它通常添加在
标记前面的
header.php
中,类似于:

<!DOCTYPE html>
<html lang="en"> 
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><?php wp_title(); ?></title>
    <?php wp_head(); ?>
</head>

对于任何在管理页面中遇到此问题的人,请使用
admin\u enqueue\u脚本
钩子而不是
wp\u enqueue\u脚本
钩子


.

替换
wp\u enqueue\u脚本('script name',get\u template\u directory\u uri()。/js/main.js',array(),'1.0.0',true)时是否看到任何更改使用
wp\u enqueue\u脚本('scriptname',get\u template\u directory\u uri()。/js/main.js')?没有任何区别,我添加了调试“echo”输出仍然是一样的。mytheme_scripts()甚至没有被调用请解释您的答案哦,在添加
之后非常感谢您的帮助
<!DOCTYPE html>
<html lang="en"> 
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><?php wp_title(); ?></title>
    <?php wp_head(); ?>
</head>