So I’m busy in WordPress. I have a theme for the site and all. It’s all working fine. Then I want to activate the new theme. BENG BENG, white screen of death. I debugged and this is the error:
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:xampphtdocswp-includesfunctions.php on line 2944
Line 2944 is just the line that throws an error. I already checked that.
Anyone ever experienced and solved this?
EDIT:
Referencing lines:
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 ) );
}
}
The error have nothing related to the code you’ve added added. It is not a WordPress core related issue, but an issue with your theme or a plugin
What the error means is that some script is enqueued way too early, ie,
wp_enqueue_script()
is hooked to a wrong hook that runs beforewp_enqueue_scripts
,admin_enqueue_scripts
, orinit
.Unfortunately this error in WordPress is a bit fague as it doesn’t tell you exactly where the problem is, just that
wp_enqueue_script
is wrongly called.You’ll need to look for all instances in your theme and plugins for
wp_enqueue_script
and check that it is properly hookedEDIT
From your comments, you have found three instances of
wp_enqueue_script
. You now need to see how it is hooked. It should look something like thisTHIS IS THE WRONG HOOK USED
is what you must check, as this is the wrong hook. This must bewp_enqueue_scripts
oradmin_enqueue_scripts
, depending on if the script is meant for front end or back endIn some of your plugins or your theme, a script may be included like this :
try to change it using this code: