PHP Notice: wp_enqueue_script was called incorrectly. Scripts and styles should not be registered

Can someone help me fix this error?

PHP 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 login_enqueue_scripts hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.0.) in /nas/content/live/greattaste/wp-includes/functions.php on line 4986

code:

function wp_auth_check_load() {
    if ( ! is_admin() && ! is_user_logged_in() ) {
        return;
    }

    if ( defined( 'IFRAME_REQUEST' ) ) {
        return;
    }

    $screen = get_current_screen();
    $hidden = array( 'update', 'update-network', 'update-core', 'update-core-network', 'upgrade', 'upgrade-network', 'network' );
    $show   = ! in_array( $screen->id, $hidden );

    /**
     * Filters whether to load the authentication check.
     *
     * Passing a falsey value to the filter will effectively short-circuit
     * loading the authentication check.
     *
     * @since 3.6.0
     *
     * @param bool      $show   Whether to load the authentication check.
     * @param WP_Screen $screen The current screen object.
     */
    if ( apply_filters( 'wp_auth_check_load', $show, $screen ) ) {
        wp_enqueue_style( 'wp-auth-check' );
        wp_enqueue_script( 'wp-auth-check' );

        add_action( 'admin_print_footer_scripts', 'wp_auth_check_html', 5 );
        add_action( 'wp_print_footer_scripts', 'wp_auth_check_html', 5 );

    }
}

Solutions

Before you can use, those two lines :

wp_enqueue_style( 'wp-auth-check' );
wp_enqueue_script( 'wp-auth-check' );

you should register those assets, inside wp_enqueue_scripts or admin_enqueue_scripts, like the following :

function my_assets() {
wp_register_style( 'wp-auth-check', 'path/to/style', $deps = array, $ver = false, $media = 'all' )
 wp_register_script( 'wp-auth-check', 'path/to/your-script', $deps = array, $ver = false, $in_footer = false )
}

add_action('wp_enqueue_scripts', 'my_assets');
or 
add_action('admin_enqueue_scripts', 'my_assets');

Similar questions

Wordpress, Error when trying to insert data >> Notice: wpdb::prepare was called incorrectly
I have the following code to insert multiple rows into my custom WordPress table. When I run the form to submit the data and insert it to the WordPress database I get the this error message: Notice: wpdb::prepare was called incorrectly. Unsupported value type (array). and Warning: mysqli_real_escape_string() expects parameter 2 to be string, The ar...
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.
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 .