Title: Function wp_enqueue_script() was called incorrectly
Last modified: October 17, 2022

---

# Function wp_enqueue_script() was called incorrectly

 *  Resolved [julian_wave](https://wordpress.org/support/users/julian_wave/)
 * (@julian_wave)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/function-wp_enqueue_script-was-called-incorrectly-2/)
 * I’m getting this notice on my widgets page.:
 * Notice: Function wp_enqueue_script() was called incorrectly. “wp-editor” script
   should not be enqueued together with the new widgets editor (wp-edit-widgets 
   or wp-customize-widgets). Please see Debugging in WordPress for more information.(
   This message was added in version 5.8.0.)
 * I think I know what’s causing it, but I don’t know how to fix it. Despite the
   notice, everything seems to be working fine. What I want to know is, how important
   is a notice like this – if it is not actually breaking anything, is it safe to
   ignore it if I can’t actually fix it?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Pratik Jain](https://wordpress.org/support/users/pratik-jain/)
 * (@pratik-jain)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/function-wp_enqueue_script-was-called-incorrectly-2/#post-16105436)
 * Hi [@julian_wave](https://wordpress.org/support/users/julian_wave/)
 * Thanks for providing the error message.
 * As per the error message, It looks like you are using the old theme or plugin
   which is not updated with WordPress standard.
 * In WordPress version 5.8, the new Block based Widget Screen is introduced. May
   be your theme or any other third party plugin which still used ‘wp_editor’ in
   Widget area which is causing this error.
 * For temporary fix, you can use below plugin
    [https://wordpress.org/plugins/classic-widgets/](https://wordpress.org/plugins/classic-widgets/)
 * OR use the custom code as given in below thread
    [https://wordpress.org/support/topic/error-in-widgets-with-new-wordpress-version-5-8-wp_enqueue_script-and-wp/](https://wordpress.org/support/topic/error-in-widgets-with-new-wordpress-version-5-8-wp_enqueue_script-and-wp/)
 * Both are temporary fix, you have to check the theme or plugin to debug the issue.
 *  Thread Starter [julian_wave](https://wordpress.org/support/users/julian_wave/)
 * (@julian_wave)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/function-wp_enqueue_script-was-called-incorrectly-2/#post-16105916)
 * Thanks [@pratik-jain](https://wordpress.org/support/users/pratik-jain/),
 * After a lot of investigation I found that 2 things were causing this error. One
   was a plugin (which I have disabled). The other was code I had added to the theme
   myself, to change the parent/child relationship of some Gutenberg blocks. The
   thread you mention is full of people with the same (or similar) problems as me,
   but most of the suggested solutions are simply to go back to the classic version
   of widgets. I need the block version of widgets to work, I can’t go back to classic.
   I think I have actually found a solution to fix my code, but it took an awful
   lot of searching online – I couldn’t find anything I could understand in the 
   WordPress official documentation.
 *  [Pratik Jain](https://wordpress.org/support/users/pratik-jain/)
 * (@pratik-jain)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/function-wp_enqueue_script-was-called-incorrectly-2/#post-16113260)
 * Hi [@julian_wave](https://wordpress.org/support/users/julian_wave/)
 * Thanks for your response. I can understand your concern.
 * WordPress has already provided the proper error message
 * > wp-editor script should not be enqueued together with the new widgets editor(
   > wp-edit-widgets or wp-customize-widgets). Please see Debugging in WordPress
   > for more information. (This message was added in version 5.8.0.)
 * So there is no documentation because various cases can cause this.
 * As you are saying there is a plugin and your child theme is causing the issue
   then they must be using any block / widget which has a “WP Editor” (TinyMce) 
   area to write the text which needs to be rewrite in the new standard.
 *  Thread Starter [julian_wave](https://wordpress.org/support/users/julian_wave/)
 * (@julian_wave)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/function-wp_enqueue_script-was-called-incorrectly-2/#post-16113957)
 * Thanks [@pratik-jain](https://wordpress.org/support/users/pratik-jain/),
 * If it is of any use to anyone, here’s what my problem was – and how I fixed it.
 * I had written some code to change the parent-child relationship of certain blocks.
 * `wp_enqueue_script( 'gutenberg-filters', get_stylesheet_directory_uri() . '/js/
   change-block-parents.js', [ 'wp-edit-post' ] );`
 * At the time I added that code, I wasn’t using any widgets. So I didn’t notice
   the error on the widgets page until long after I had added the code.
 * However, I did start using widgets later, and when this code loaded with the 
   widgets screen (and also the options page), it created an error because it used
   wp-edit-post.
 * In the end, I came up with the following:
 *     ```
       function enqueue_change_block_parents_script() {
         global $pagenow;
         if ( $pagenow != 'post.php' && $pagenow != 'page.php' && $pagenow != 'widgets.php' ) {
           return;
         }
         if ( $pagenow == 'post.php' || $pagenow == 'page.php' ) {
           wp_enqueue_script( 'gutenberg-filters', get_stylesheet_directory_uri() . '/js/change-block-parents.js', [ 'wp-edit-post' ] );
         } else if ( $pagenow == 'widgets.php' ) {
           wp_enqueue_script( 'gutenberg-filters', get_stylesheet_directory_uri() . '/js/change-block-parents.js', [ 'wp-edit-widgets' ] );
         }
       }
       add_action( 'admin_enqueue_scripts', 'enqueue_change_block_parents_script' );
       ```
   
 * I don’t know how well-coded it is, but it seems to do the job. Everything works
   as intended, and I don’t get any more error messages.`

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Function wp_enqueue_script() was called incorrectly’ is closed to new
replies.

## Tags

 * [enqueue](https://wordpress.org/support/topic-tag/enqueue/)
 * [widgets](https://wordpress.org/support/topic-tag/widgets/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [julian_wave](https://wordpress.org/support/users/julian_wave/)
 * Last activity: [3 years, 7 months ago](https://wordpress.org/support/topic/function-wp_enqueue_script-was-called-incorrectly-2/#post-16113957)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
