Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

wp_enqueue_script was called incorrectly.

Hello, having built out most of my first wp theme, when using the theme-check I get an error at the top of dashboard which says: 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 /Users/................/wp-includes/functions.php on line 3370 I have checked on Google for possible solutions but not finding any that makes sense to me unfortunately! Any help would be great! Thanks, Nic

3 Answers

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

Please post your code so we can see what's going on :)

Hi Zac :) Thanks for your reply!

Here below is in my functions.php file and is the only place I can think where I have enqueued scripts (unless perhaps a plugin? - those active are: Advanced Custom Fields, Custom Post Type UI, Gravity Forms)


function ptmjdk_theme_styles() {

wp_enqueue_style( 'googlefonts_css', 'http://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700,400italic|Courgette' );

wp_enqueue_style( 'main_css', get_template_directory_uri() . '/style.css' );

wp_enqueue_style( 'responsive_css', get_template_directory_uri() . '/css/responsive.css' );

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

function ptmjdk_theme_js() {

wp_enqueue_script( 'modernizr_js', get_template_directory_uri() . '/js/modernizr.js', '', '', false );
wp_enqueue_script( 'script_js', get_template_directory_uri() . '/js/script.js', array('jquery'), '', true );

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


Please let me know there is somewhere else I should be looking?

Kind regards, Nic

function ptmjdk_theme_styles() {

    wp_enqueue_style( 'googlefonts_css', 'http://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700,400italic|Courgette' );

    wp_enqueue_style( 'main_css', get_template_directory_uri() . '/style.css' );

    wp_enqueue_style( 'responsive_css', get_template_directory_uri() . '/css/responsive.css' );

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

function ptmjdk_theme_js() {

    wp_enqueue_script( 'modernizr_js', get_template_directory_uri() . '/js/modernizr.js', '', '', false );
    wp_enqueue_script( 'script_js', get_template_directory_uri() . '/js/script.js', array('jquery'), '', true );

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