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:xampphtdocswp-includesfunctions.php on line 2944

Line 2944 is just the line that throws an error. I already checked that.

Read More

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 ) );
    }
}

Related posts

Leave a Reply

2 comments

  1. 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

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