WP_debug错误与wp_enqueue

我得到两种类型的错误,我不知道如何解决。

你可以在这里看到错误: 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(’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

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

链接到txt

使用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

更新:

如果您在functions.php或任何plugin file直接调用任何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 }