我遇到了两种我不知道如何解决的错误。
您可以在此处查看错误: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()。 '/包括/ metabox / smart_meta_box / smart_meta_fields /布局编辑器/';
wp_enqueue_script('mcolorpicker',$ path。'js / mColorPicker.js',array('jquery'));
wp_enqueue_style('selected',$ 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('selected-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'));
我认为前端显示器也可能需要它们。我如何以正确的方式排列这些?
以下是发生两个未定义属性错误的代码:
答案 0 :(得分:2)
使用wp_enqueue_scripts操作来调用此函数,或 admin_enqueue_scripts在管理员端调用它。
要将其加载到前端,请使用
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
。
<强>更新强>
如果您在wp_register_script(xxx)
或任何wp_enqueue_style(xxx)
中直接进行了functions.php
或plugin file
来电,请在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
}