首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有WP_debug错误的wp_enqueue

带有WP_debug错误的wp_enqueue
EN

Stack Overflow用户
提问于 2012-07-05 00:17:31
回答 1查看 4.1K关注 0票数 2

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

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

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

代码语言:javascript
复制
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有个电话:

代码语言:javascript
复制
function my_init() {
if (!is_admin()) {
    wp_enqueue_script('jquery');
}
}
add_action('init', 'my_init');

第二种错误类型是:

代码语言:javascript
复制
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(“色选器”,$path .)‘’js/m科罗拉多Picker.js‘,数组(’jquery‘);

Wp_enqueue_style(“”,$path .‘'css/chosen.css');

Wp_enqueue_style(“内容-布局”,$path .‘'css/content-layout.css');

Wp_enqueue_script(‘jquery’,$path .‘'js/jquery.json.js’数组(‘jquery’);

Wp_enqueue_script(‘jquery jquery’),$path。‘'js/chosen.jquery.min.js',数组(’jquery‘);

Wp_enqueue_script(‘内容-布局-js’,$path .‘'js/content-layout.js',数组(’jquery‘,’jquery sortable‘);

我认为他们也可能需要前端显示以及。我怎样才能以正确的方式排队呢?

  • 更新2

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

链接到txt

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-05 01:24:32

使用wp_enqueue_scripts操作来调用这个函数,或者使用admin_enqueue_scripts在管理端调用它。

要将其加载到前端,请使用

代码语言:javascript
复制
add_action('wp_enqueue_scripts', 'my_scripts_method');
function my_scripts_method() {
    wp_enqueue_script('jquery');
}

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

代码语言:javascript
复制
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或any plugin file中,则在wp_enqueue_script处理程序中使用它们,如下所示

代码语言:javascript
复制
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
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11336578

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档