21 posts
  • Bought between 100 and 499 items
  • Has been a member for 4-5 years
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

3192 posts
  • Sold between 5 000 and 10 000 dollars
  • United States
  • Bought between 10 and 49 items
  • Has been a member for 4-5 years
  • Exclusive Author
organicbee says

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

1148 posts
  • Referred between 1 and 9 users
  • Sold between 1 000 and 5 000 dollars
  • Has been a member for 4-5 years
  • Bought between 10 and 49 items
  • Exclusive Author
  • Envato Studio (Microlancer) Beta Tester
  • United States
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' );
3192 posts
  • Sold between 5 000 and 10 000 dollars
  • United States
  • Bought between 10 and 49 items
  • Has been a member for 4-5 years
  • Exclusive Author
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
  • Bought between 100 and 499 items
  • Has been a member for 4-5 years
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
  • Bought between 100 and 499 items
  • Has been a member for 4-5 years
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
  • Bought between 10 and 49 items
  • Has been a member for 3-4 years
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
  • Bought between 1 and 9 items
  • Elite Author
  • Exclusive Author
  • Has been a member for 3-4 years
  • Most Wanted Bounty Winner
  • Referred between 200 and 499 users
  • Sold between 100 000 and 250 000 dollars
worthapost says

I am having same message issue with visual composer

75 posts
  • Referred between 1 and 9 users
  • Exclusive Author
  • Has been a member for 7-8 years
  • Bought between 50 and 99 items
  • United States
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’ ) );

75 posts
  • Referred between 1 and 9 users
  • Exclusive Author
  • Has been a member for 7-8 years
  • Bought between 50 and 99 items
  • United States
SimpleRain says

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

by
by
by
by
by
by