WP_debug错误与wp_enqueue [英] WP_debug errors with wp_enqueue

查看:209
本文介绍了WP_debug错误与wp_enqueue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



您可以在这里看到错误: http://www.brainbuzzmedia.com/themes/vertex/



第一个类型发生两次,如下所示:

 注意:wp_enqueue_script被错误地调用。在wp_enqueue_scripts,admin_enqueue_scripts或init hook之前,脚本和样式不应该被注册或排队。有关详细信息,请参阅WordPress中的调试。 (该消息已在版本3.3中添加)在/home/admin/buzz/themes/vertex/wp-includes/functions.php第3587行

我在functions.php中有一个电话:

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

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

 注意:未定义的属性:stdClass :: $ slider_height在/vertex/wp-content/themes/vertex/slider_settings.php第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('selected',$ path。'css / chosen.css');



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



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



wp_enqueue_script('selected-jquery',$ path。 .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'); 
函数my_admin_scripts_method(){
wp_enqueue_script('jquery');
}

参考: Codex



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



更新:



如果您有任何 wp_register_script(xxx) wp_enqueue_style(xxx) functions.php 或您的任何插件文件直接在 wp_enqueue_script 处理程序如下

  add_action('wp_enqueue_scripts','my_scripts_method'); 
function my_scripts_method(){
wp_register_script('xxx'); //用有效的脚本名称替换xxx
wp_enqueue_script('jquery');
wp_enqueue_style(xxx)//如果你有
}


I am getting two types of errors that I don't know how to fix.

You can see the errors here: http://www.brainbuzzmedia.com/themes/vertex/

The first type occurs twice and looks like this:

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

I have a call in functions.php:

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

The second error type is this:

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

No matter where (inside or outside of if statements or both) I define these variables they are still giving me this error.

* update

I have some other scripts enqueued in a subfolder of the theme's files, mostly used for admin area.

$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'));

I think they may also be needed for front end display as well. How would I enqueue these the right way?

  • update 2

Here is the code where two of the undefined property errors occur:

link to txt

解决方案

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

To load it for front end, use

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

To load it for admin, use

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

Reference: Codex.

The second error occured because jQuery is not loaded.

Update:

If you hae any wp_register_script(xxx)orwp_enqueue_style(xxx)call in yourfunctions.php or in your any plugin file directly then use them inside wp_enqueue_script handler as follows

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
}

这篇关于WP_debug错误与wp_enqueue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆