124 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
  • Has sold $10,000+ on Envato Market
+3 more
ThemeChills says

Hi guys,

I’m in the process of doing the final debug to my theme and I am at a road block.

I get the below error when I set my wp-config debug settings to true.


Notice: 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. Please see Debugging in WordPress for more information. (This message was added in version 3.3.) in C:\path\path\path\wp-includes\functions.php on line 3049

Isn’t this part of WP core and not the theme functions.php? Why would I be prompted of this?

Would appreciate your thoughts, thanks in advance.

Leo

1243 posts
  • Provided great contribution to our forums
  • Has been part of the Envato Community for over 4 years
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+6 more
Smartik says

The message comes from wp-includes\functions.php but the error is in your theme.

Here looks like you have used the function `wp_enqueue_script` somewhere in your code and didn’t registered it using wp_enqueue_scripts.

Here’s the right way to do this, and this should go in the function.php of your theme:
function my_custom_scripts(){
    wp_enqueue_script('my_script');
    wp_enqueue_script('another_script');
}
add_action('wp_enqueue_scripts','my_custom_scripts');
124 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
  • Has sold $10,000+ on Envato Market
+3 more
ThemeChills says

The message comes from wp-includes\functions.php but the error is in your theme.

Here looks like you have used the function `wp_enqueue_script` somewhere in your code and didn’t registered it using wp_enqueue_scripts.

Here’s the right way to do this, and this should go in the function.php of your theme:
function my_custom_scripts(){
    wp_enqueue_script('my_script');
    wp_enqueue_script('another_script');
}
add_action('wp_enqueue_scripts','my_custom_scripts');

Thanks @Smartik,

I’ll do a global search for this and then report back. I thought it could have been in my functions.php but the scripts are registered and enqueued correctly there…

Will look into it.

124 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
  • Has sold $10,000+ on Envato Market
+3 more
ThemeChills says

So I located all instances of where I was enqueuing and registering scripts. It seems I am following the correct implementation.

In turn, I decided to do a drastic test. This being, remove all code from within the index.php and functions.php, essentially have these blank. Error still persists.

Next, I downloaded a copy of the latest ‘Twenty Fourteen’ theme and activated it. Error still persists.

Any ideas what could be happening here?

I’m at a loss…

124 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
  • Has sold $10,000+ on Envato Market
+3 more
ThemeChills says

I think a plugin I have installed is causing the issue. Will report back shortly…

124 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
  • Has sold $10,000+ on Envato Market
+3 more
ThemeChills says

Ok, so the offending code was actually in the plugin. I fixed up how the enqueuing process works and errors no longer show. Woohoo!

Leo

by
by
by
by
by
by