Notice: wp_deregister_script was called incorrectly
-
This notice which is new in WP 3.3 is caused by the common practice in themes and plugins of using wp_register_script in open code within a php file such as functions.php. This code needs to be run in the wp_include_scripts action which is currently not documented in the Plugin API. If your theme or plugin includes code like:
wp_deregister_script('jquery'); wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"), false, '1.7.1'); wp_enqueue_script('jquery');
it now needs to be something like:
function mytheme_enqueue_scripts() { wp_deregister_script('jquery'); wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"), false, '1.7.1'); wp_enqueue_script('jquery'); } add_action('wp_enqueue_scripts', 'mytheme_enqueue_scripts');
Plugin and theme authors should fix this immediately as it’s undecipherable to average users given that the message does not include the module and line that actually caused the problem.
The wp_register_scripts action is documented in script_loader.php:
* Wrapper for do_action('wp_enqueue_scripts') * * Allows plugins to queue scripts for the front end using wp_enqueue_script(). * Runs first in wp_head() where all is_home(), is_page(), etc. functions are available. * * @since 2.8
Wouldn’t it be nice if WP just threw exceptions when it detects a Notice or higher error. If you can’t figure out where the offender is, try adding this inside the doing_it_wrong function in wp_includes/functions.php (currently at line 3585):
throw new Exception("Testing");
This will cause a stack trace to be printed and your site to die at the error. After that it’s easy to find and fix.
I hope this helps.
/peter
- The topic ‘Notice: wp_deregister_script was called incorrectly’ is closed to new replies.