wp_deregister_script 调用不正确

wp_deregister_script 如果运行的比较早,会报出个错误的提示。修改的方法也很简单。找到调用的代码写在 add_action('wp_enqueue_scripts', ....) 中即可。

wp_deregister_script 调用不正确 的错误提示

Notice: wp_deregister_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 l10n handle. Please see Debugging in WordPress for more information. (This message was added in version 3.3.0.) in /html/www.wpcode.com/webroot/wp-includes/functions.php on line 

这种错误一般发生在用户的代码中,一般是插件或者主题中。搜索一下找到,修改一下啊。比如我今天就发现一个

find . -name "*.php" | xargs grep "wp_deregister_script"

修改为


wp_deregister_script('l10n'); # 修改为下面方式

add_action('wp_enqueue_scripts', function() {
    wp_deregister_script('l10n');
});