128 posts
  • Has sold $10,000+ on Envato Market
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
+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

1278 posts
  • 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
  • Has collected 50+ items on Envato Market
+5 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');
128 posts
  • Has sold $10,000+ on Envato Market
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
+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.

128 posts
  • Has sold $10,000+ on Envato Market
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
+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…

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

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

128 posts
  • Has sold $10,000+ on Envato Market
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
+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

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by