Notice: wp_enqueue_script was called incorrectly

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:\xampp\htdocs\wp-includes\functions.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 ) );
    }
}

Solutions

In some of your plugins or your theme, a script may be included like this :

wp_enqueue_script( string $handle, string $src = '', array $deps = array(), string|bool|null $ver = false, bool $in_footer = false )

try to change it using this code:

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

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 before wp_enqueue_scripts , admin_enqueue_scripts , or init .

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 hooked

EDIT

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 this

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 is what you must check, as this is the wrong hook. This must be wp_enqueue_scripts or admin_enqueue_scripts , depending on if the script is meant for front end or back end

Similar questions

Notice: wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder
With code above its working completely fine only problem i am getting this Notice: when debug mode is on. And i shouldn't have any notices. Notice: wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder. Is there any suggestion? I know removing prepare( would take away the problem. But i want to keep the...
Notice: register_uninstall_hook was called incorrectly
I automatically updated my wordpress installation to the latest version. Everything looked normal unit "updating database..." where it got stuck. I waited for a long while and then closed the page, since nothing was happening. Then I got a error message saying something about maintenance, which I got rid of after deleting the maintenance file. Word...
Woocommerce - internal server error: Notice: id was called incorrectly
My site has a problem. On checkout I get the Internal server error. I have read almost all the solutions provided on forums and even on this forum but none proved to solve this problem. Here is the error log below. Notice: id was called incorrectly. Order properties should not be accessed directly. Backtrace: require(‘wp-blog-header.php’), require_...
Notice: register_rest_route was called incorrectly
In my Wordpress site, this issue appears when adding or editing posts. Note: I didn't make any WP update or any plugin update on the site. Any idea to fix this issue? Thank you.
string(2) "id" Notice: id was called incorrectly. Product properties should not be accessed directly. Backtrace:
string(2) "id" Notice: id was called incorrectly. Product properties should not be accessed directly. Backtrace: require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/plugins/woocommerce/templates/single-product.php'), wc_get_template_part, load_template, require('/plugins/woocommerce/templates/content-...
Getting notice is wordpress "WP_Scripts::localize was called incorrectly"
Complete message: Notice: WP_Scripts::localize was called incorrectly. The $l10n parameter must be an array. To pass arbitrary data to scripts, use the wp_add_inline_script() function instead. Please see Debugging in WordPress for more information. (This message was added in version 5.7.0.) in /home3/dduconne/public_html/wp-includes/functions.php o...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy .