所以我忙于Wordpress。我有一个网站的主题和所有。一切正常。然后我想激活新主题。 BENG BENG,白屏死亡。我调试了,这是错误:
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 C:\xampp\htdocs\wp-includes\functions.php on line 2944
第2944行就是抛出错误的行。我已经检查过了。
有没有人经历过并解决了这个问题?
编辑:
引用行:
function _doing_it_wrong( $function, $message, $version ) {
do_action( 'doing_it_wrong_run', $function, $message, $version );
// Allow plugin to filter the output error trigger
if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true ) ) {
$version = is_null( $version ) ? '' : sprintf( __( '(This message was added in version %s.)' ), $version );
$message .= ' ' . __( 'Please see <a href="http://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information.' );
trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ) );
}
}
答案 0 :(得分:1)
错误与您添加的代码无关。它不是与Wordpress核心相关的问题,而是您的主题或插件的问题
错误的含义是某些脚本过早排队,即wp_enqueue_script()
被挂钩到在wp_enqueue_scripts
,admin_enqueue_scripts
或{{1}之前运行的错误挂钩}。
不幸的是,Wordpress中的这个错误有点模糊,因为它没有告诉你问题的确切位置,只是错误地调用了init
。
您需要查找主题和wp_enqueue_script
插件中的所有实例,并检查它是否已正确挂钩
修改强>
根据您的评论,您找到了wp_enqueue_script
的三个实例。你现在需要看看它是如何被钩住的。它应该看起来像这样
wp_enqueue_script
function some_function_name(){
wp_enqueue_script(ALL THE SCRIPT DETAILS IN HERE);
}
add_action( 'THIS IS THE HOOK THAT IS IMPORTANT', 'some_function_name');
是你必须检查的,因为这是错误的钩子。这必须是THIS IS THE WRONG HOOK USED
或wp_enqueue_scripts
,具体取决于脚本是用于前端还是后端
答案 1 :(得分:0)
在某些插件或主题中,可能会包含如下脚本:
wp_enqueue_script( string $handle, string $src = '', array $deps = array(), string|bool|null $ver = false, bool $in_footer = false )
尝试使用此代码更改它:
<?php
function wpb_adding_scripts() {
wp_register_script('my_amazing_script', plugins_url('amazing_script.js', __FILE__), array('jquery'),'1.1', true);
wp_enqueue_script('my_amazing_script');
}
add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' );
?>