gpt4 book ai didi

php - wp_enqueue 的 WP_debug 错误

转载 作者:行者123 更新时间:2023-12-01 04:20:15 27 4
gpt4 key购买 nike

我遇到两种类型的错误,但我不知道如何修复。

您可以在此处查看错误:http://www.brainbuzzmedia.com/themes/vertex/

第一种类型出现两次,如下所示:

Notice: wp_enqueue_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or init hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.) in /home/admin/buzz/themes/vertex/wp-includes/functions.php on line 3587

我在functions.php中有一个调用:

function my_init() {
if (!is_admin()) {
wp_enqueue_script('jquery');
}
}
add_action('init', 'my_init');

第二个错误类型是这样的:

Notice: Undefined property: stdClass::$slider_height in /vertex/wp-content/themes/vertex/slider_settings.php on line 32

无论我在哪里(在 if 语句内部或外部或两者)定义这些变量,它们仍然会给我这个错误。

*更新

我在主题文件的子文件夹中排队了一些其他脚本,主要用于管理区域。

$path = get_template_directory_uri() 。 '/includes/metabox/smart_meta_box/smart_meta_fields/layout-editor/';

wp_enqueue_script('mcolorpicker', $path . 'js/mColorPicker.js', array('jquery'));

wp_enqueue_style('chosen', $path . 'css/chosen.css');

wp_enqueue_style('content-layout', $path .'css/content-layout.css');

wp_enqueue_script('jquery-json', $path . 'js/jquery.json.js', array('jquery'));

wp_enqueue_script('chosen-jquery', $path . 'js/chosen.jquery.min.js', array('jquery'));

wp_enqueue_script('content-layout-js', $path . 'js/content-layout.js', array('jquery', 'jquery-ui-sortable'));

我认为前端显示也可能需要它们。我如何以正确的方式将它们排入队列?

  • 更新2

以下是发生两个未定义属性错误的代码:

link to txt

最佳答案

Use the wp_enqueue_scripts action to call this function, or admin_enqueue_scripts to call it on the admin side.

要为前端加载它,请使用

add_action('wp_enqueue_scripts', 'my_scripts_method');
function my_scripts_method() {
wp_enqueue_script('jquery');
}

要为管理员加载它,请使用

add_action('admin_enqueue_scripts', 'my_admin_scripts_method');
function my_admin_scripts_method() {
wp_enqueue_script('jquery');
}

引用: Codex .

第二个错误发生是因为 jQuery 未加载。

更新:

如果您在functions.php或任何中调用任何wp_register_script(xxx)wp_enqueue_style(xxx)直接使用插件文件,然后在 wp_enqueue_script 处理程序中使用它们,如下所示

add_action('wp_enqueue_scripts', 'my_scripts_method');
function my_scripts_method() {
wp_register_script('xxx'); // replace the xxx with valid script name
wp_enqueue_script('jquery');
wp_enqueue_style(xxx) // if you have any
}

关于php - wp_enqueue 的 WP_debug 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11336578/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com