- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我遇到两种类型的错误,但我不知道如何修复。
您可以在此处查看错误: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'));
我认为前端显示也可能需要它们。我如何以正确的方式将它们排入队列?
以下是发生两个未定义属性错误的代码:
最佳答案
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/
我遇到两种类型的错误,但我不知道如何修复。 您可以在此处查看错误:http://www.brainbuzzmedia.com/themes/vertex/ 第一种类型出现两次,如下所示: Notice
我在我的 wp-config 文件中启用了错误: define('WP_DEBUG', true); 但是我有一个空白的白页。未列出任何错误。 最佳答案 插入 wp-config.php 文件的以下代
我是一名优秀的程序员,十分优秀!