Akasha Malik
Akasha Malik

Reputation: 11

how can solve : wp_enqueue_style was called incorrectly and script?

how are you I have an issue when I login to the admin panel I face the following errors

Notice: wp_enqueue_style 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. This notice was triggered by the lity-style handle. Please see Debugging in WordPress for more information. (This message was added in version 3.3.0.) in /home/customer/www/remny.com/public_html/wp-includes/functions.php on line 5667

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. This notice was triggered by the lity-script handle. Please see Debugging in WordPress for more information. (This message was added in version 3.3.0.) in /home/customer/www/remny.com/public_html/wp-includes/functions.php on line 5667

let me know how can I fix

Upvotes: 0

Views: 4885

Answers (1)

Sagar Bahadur Tamang
Sagar Bahadur Tamang

Reputation: 2709

In WordPress, you have to enqueue scripts and styles with corresponding function wp_enqueue_script and wp_enqueue_style. But, remember these functions should be only called after wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks are triggered.

Those hooks are called in different scenarios.

  1. wp_enqueue_scripts : This hook is triggered for frontend/public side of the WordPress.
  2. admin_enqueue_scripts: This hook is only triggered for the admin side of the WordPress or you can say when the URL contains the wp-admin.
  3. login_enqueue_scripts: It is a particular hook triggered only on the login page of WordPress which is usually accessed through http://example.com/wp-admin

An example is to enqueue scripts on the public side of the page.

/**
 * Enqueue a script with jQuery as a dependency.
 */
function wpdocs_scripts_method() {
    wp_enqueue_script( 'custom-script', get_stylesheet_directory_uri() . '/js/custom_script.js', array( 'jquery' ) );
}
add_action( 'wp_enqueue_scripts', 'wpdocs_scripts_method' );

As you can see, the function wp_enqueue_script in only called after the wp_enqueue_scripts hook is triggered.

Reference:

  1. https://developer.wordpress.org/reference/functions/wp_enqueue_script/
  2. https://developer.wordpress.org/reference/functions/wp_enqueue_style/

Upvotes: 1

Related Questions