最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp enqueue script - wp_enqueue_script called incorrectly

programmeradmin2浏览0评论

I've spent the better part of four hours trying to solve this freaking problem and am losing my mind.

[16-May-2018 20:57:32 UTC] PHP Notice:  wp_enqueue_script was called 
<strong>incorrectly</strong>. Scripts and styles should not be 
registered or enqueued until the <code>wp_enqueue_scripts</code>, 
<code>admin_enqueue_scripts</code>, or 
<code>login_enqueue_scripts</code> hooks. Please see <a 
href="">Debugging 
in WordPress</a> for more information. (This message was added in 
version 3.3.0.) in ../html/wp-includes/functions.php on line 4147

I've never encountered this error before, and have been a WordPress developer for years. I've been working on this theme for months, and this error suddenly started showing up today. No plugin / Core updates. In fact, no changes to the way styles/scripts are enqueued.

This error only shows on the backend, and it logs to the debug file constantly, even without page refreshes.

I've done the usual and disabled all plugins... Error still appears. I removed all plugins from plugins directory... Error still appears. I've gone through my theme and literally removed every single reference to wp_enqueue_script and the error STILL appears.

I literally have no styles and no scripts being loaded (correctly or incorrectly), no reference to wp_enqueue_script, or any reference to any of the acceptable hooks, and this error still shows up.

If I disable the theme, all is well. What on earth could be the problem? Is there any way to see what script is actually throwing the error?

I've spent the better part of four hours trying to solve this freaking problem and am losing my mind.

[16-May-2018 20:57:32 UTC] PHP Notice:  wp_enqueue_script was called 
<strong>incorrectly</strong>. Scripts and styles should not be 
registered or enqueued until the <code>wp_enqueue_scripts</code>, 
<code>admin_enqueue_scripts</code>, or 
<code>login_enqueue_scripts</code> hooks. Please see <a 
href="https://codex.wordpress/Debugging_in_WordPress">Debugging 
in WordPress</a> for more information. (This message was added in 
version 3.3.0.) in ../html/wp-includes/functions.php on line 4147

I've never encountered this error before, and have been a WordPress developer for years. I've been working on this theme for months, and this error suddenly started showing up today. No plugin / Core updates. In fact, no changes to the way styles/scripts are enqueued.

This error only shows on the backend, and it logs to the debug file constantly, even without page refreshes.

I've done the usual and disabled all plugins... Error still appears. I removed all plugins from plugins directory... Error still appears. I've gone through my theme and literally removed every single reference to wp_enqueue_script and the error STILL appears.

I literally have no styles and no scripts being loaded (correctly or incorrectly), no reference to wp_enqueue_script, or any reference to any of the acceptable hooks, and this error still shows up.

If I disable the theme, all is well. What on earth could be the problem? Is there any way to see what script is actually throwing the error?

Share Improve this question asked May 16, 2018 at 21:15 idealbrandonidealbrandon 1532 silver badges8 bronze badges 5
  • Hi silly question do you have debug set to true on your local enviro? That might give you some more insight. The best clue though is the functions.php error on line 4147. It could be you have had a Warning for ages that's now turned into a full Error and is now broken (I assume you're on WP 4.9.5?) – Nathaniel Flick Commented May 16, 2018 at 21:20
  • yes, I have debugging turned on and logging to debug.log. I understand that this is only a notice, but it makes it a pain to debug other issues with this constantly spamming my debug log. – idealbrandon Commented May 16, 2018 at 21:36
  • As for checking functions.php ln 4147, this is actually the WP Core (wp-includes) functions.php file, and all it is is the wrapper function that outputs the error: trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ) ); – idealbrandon Commented May 16, 2018 at 21:37
  • Have you gone back to default enqueuing in your theme's functions.php? If error goes away it's one of your enqueues in the wrong place, perhaps. Wish I could do more here but can only speculate. – Nathaniel Flick Commented May 16, 2018 at 21:42
  • I've completely removed ALL enqueues and the error still exists. Literally loading no custom CSS or JS, not enqueuing anything at all. – idealbrandon Commented May 16, 2018 at 23:01
Add a comment  | 

1 Answer 1

Reset to default 2

UGH.

I solved this. I'm an idiot. I had a file in my theme named admin.php that was setting up wp-admin handlers and the like for a portion of my application.

I was including this via include_once( 'admin.php' ) from its parent file, and apparently that was calling the main wp-core admin.php file. So yeah. Hours of debugging because I didn't specify an absolute path. smh.

发布评论

评论列表(0)

  1. 暂无评论