I have this error notice 'wp_enqueue_script was called incorrectly' in my plugin

I have read all the previous posts about this but can't seem to get my head around what is wrong with my code. This is in a plugin that I have written. I thought I had it sorted but looks like I haven't is it the order in which I am calling these?

function gedshow_ajaxurl() {
    echo '<script type="text/javascript">
        var ajaxurl = "' . admin_url('admin-ajax.php') . '";
        </script>';
}
add_action('wp_head', 'gedshow_ajaxurl');

wp_enqueue_script('jquery');
add_action('admin_menu', 'gedshow_setup_menu');

function mw_enqueue_color_picker( $hook_suffix ) {
    // first check that $hook_suffix is appropriate for your admin page
    wp_enqueue_style( 'wp-color-picker' );
    wp_enqueue_script( 'my-script-handle', plugins_url('my-script.js', __FILE__ ), array( 'wp-color-picker' ), false, true );
}

add_action( 'admin_enqueue_scripts', 'mw_enqueue_color_picker' );

function gedshow_enqueue_styles(){
    $file_url = plugins_url('gedshow.css',__FILE__);
    wp_enqueue_style('sp_stylesheet',$file_url);
}
add_action( 'wp_enqueue_scripts','gedshow_enqueue_styles');

Solutions

Removing wp_enqueue_script('jquery'); will fix your problem.

Put jquery into deps parameter of wp_enqueue_script function.

Similar questions

wp_enqueue_script was called <strong>incorrectly</strong>. Scripts and styles
I am not a developer, but I have a theme that is giving me the error 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. I have read some solutions where they suggest to change to do: But the code in my website does not...
Notice: map_meta_cap was called incorrectly
I created an external script to import json data into a custom post type that uses wp-load.php. Everything works fine but after every update I get the message Im calling the script inside a child theme and post_type_exists returns false but works fine... Ive seen a similar notice in a core track thread but it talks about comments being the issue an...
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...
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 .