83 posts
  • Attended a Community Meetup
  • Australia
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
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

1068 posts
  • Forum Superstar
  • Most Wanted Bounty Winner
  • Envato Studio (Microlancer) Beta Tester
  • Author had a Free File of the Month
  • Bought between 50 and 99 items
  • Referred between 50 and 99 users
  • Europe
  • Has been a member for 3-4 years
  • Exclusive Author
+1 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');
83 posts
  • Attended a Community Meetup
  • Australia
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
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.

83 posts
  • Attended a Community Meetup
  • Australia
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
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…

83 posts
  • Attended a Community Meetup
  • Australia
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
ThemeChills says

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

83 posts
  • Attended a Community Meetup
  • Australia
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
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