21 posts
  • Has been part of the Envato Community for over 5 years
  • Has collected 100+ items on Envato Market
andiszek says

Hi all, i`m going trough the final checks with my theme and there is a WP_Debug notice that`s really bugging me:

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 init hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.) in /home/....serverpath…./wp-includes/functions.php on line 2748

the notice is visible in both frontend and backend (with wp_debug turned on).

has anyone else experienced this notice? could you please help with an advice or solution? i can`t seem to find any solution in the codex or on other websites.

is this notice a reason for rejection?

thanks in advance, andi

3425 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
  • Has been part of the Envato Community for over 4 years
+1 more
organicbee says

yes its a reason for rejection, how are you enqueuing your scripts?

1148 posts
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
fillerspace says

Maybe you are calling wp_enqueue_script directly from your functions.php file (or another file you included from it). Instead you should create a function that calls wp_enqueue_script and then register it using the wp_enqueue_scripts hook.

function loadMyScripts()
{
    wp_register_script( 'myscript', 'js/myscript.js' );
    wp_enqueue_script( 'myscript' );
}

add_action( 'wp_enqueue_scripts','loadMyScripts' );
3425 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
  • Has been part of the Envato Community for over 4 years
+1 more
organicbee says

Maybe you are calling wp_enqueue_script directly from your functions.php file (or another file you included from it). Instead you should create a function that calls wp_enqueue_script and then register it using the wp_enqueue_scripts hook.
function loadMyScripts()
{
    wp_register_script( 'myscript', 'js/myscript.js' );
    wp_enqueue_script( 'myscript' );
}

add_action( 'wp_enqueue_scripts','loadMyScripts' );

It actually looks like he’s using the wrong hook

21 posts
  • Has been part of the Envato Community for over 5 years
  • Has collected 100+ items on Envato Market
andiszek says

Hi OrganicBeeMedia & Fillerspace, thanks for your replies.

i will try out the function today and will let you know how it works.

until now, i`ve tried to enqueue the scripts in 2 ways:

1. register in functions PHP and enqueue directly in <head>

functions.php

function my_init_method() {
    if (!is_admin()) {

wp_register_script ( // SuperFish
          'superfish',
          get_template_directory_uri() . '/js/nav/superfish/superfish.js',
          array('jquery'), //requires jQuery
          1.48, //Version Nr
          false //loads in footer
        );

    }
}    
add_action('init', 'my_init_method');

----

header.php

<?php wp_enqueue_script( 'superfish' ); ?>

2. enqueue in functions.php (same as above) and add a function to register all scripts”

function register_all_styles()
{

wp_enqueue_script( 'superfish' );

}// end register_all_styles()

add_action('wp_enqueue_scripts','register_all_styles');

i will try out your suggestion to register and enqueue the scripts in the same function.

thanks again, andi

21 posts
  • Has been part of the Envato Community for over 5 years
  • Has collected 100+ items on Envato Market
andiszek says

Hi all, sorry for the late reply, i had some deadlines :(

i fixed the problem this way (in functions.php):

function my_init_method() {
    if (!is_admin()) {

wp_register_script ( // SuperFish
          'superfish',
          get_template_directory_uri() . '/js/nav/superfish/superfish.js',
          array('jquery'), //requires jQuery
          1.48, //Version Nr
          false //loads in footer
        );

}
}    
add_action('wp_enqueue_scripts', 'my_init_method');

and

function register_all_styles()
{
wp_enqueue_script( 'superfish' ); // Enqueue Superfish Menu
}
add_action('wp_enqueue_scripts','register_all_styles');

hope this will help someone in the future.

thanks, andi

1 post
  • Has been part of the Envato Community for over 4 years
  • Has collected 10+ items on Envato Market
sunrayshining says

Hi, I’m new to PHP.

Just installed RightNow theme at www.seedposthouse.co.za Theme is ajax based and only works with page navi plugin, but bombs on other kinds of plugins.

Site seems to be working okay, but I get this error when checking: “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 init hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.) in /usr/www/users/seedmmpyww/seedposthouse.co.za/wp-includes/functions.php on line 2959 Notice: wp_enqueue_style was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or init hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.) in /usr/www/users/seedmmpyww/seedposthouse.co.za/wp-includes/functions.php on line 2959”

Any suggestions most welcome!

I’m guessing that the theme isn’t up to date with wp3.5.1 and needs tweaking, but I’m clueless at this.

Thanks in Advance, W.

12 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 200+ members
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has collected 1+ items on Envato Market
+3 more
worthapost says

I am having same message issue with visual composer

77 posts
  • Has referred 1+ members
  • Has collected 50+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Has been part of the Envato Community for over 7 years
+1 more
SimpleRain says

I am using admin-print-styles for my scripts, and it got soft rejected. I am confused.

add_action( ‘admin_print_styles-’ . $this->page, array( &$this, ‘_enqueue’ ) );

77 posts
  • Has referred 1+ members
  • Has collected 50+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Has been part of the Envato Community for over 7 years
+1 more
SimpleRain says

bah, added 4 lines of code to replace 1 hook. Bah.

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