0

I've suddenly had an issue that neither admin_enqueue_scripts or wp_register_script are working properly, they were working fine for a while but suddenly stopped working.

In the following function, the first wp_register_script is working fine and loading modernizr, and the wp_enqueue_style is working fine and loading globalstyle, but neither the require or the global scripts are loading.

function theme_enqueue_scripts(){
    wp_register_script('modernizr', get_stylesheet_directory_uri()  . '/js/modernizr.js');

    wp_register_script('require', get_stylesheet_directory_uri()  . '/js/vendor/requirejs/require.js', array(), false, true);

    wp_register_script('global', get_stylesheet_directory_uri()  . '/js/global.js', array('require'), false, true);

    wp_enqueue_style('globalstyle', get_stylesheet_directory_uri()  . '/css/global.css');
}
add_action('wp_enqueue_scripts', 'theme_enqueue_scripts');

And the following function doesn't load admin-nav.js using admin_enqueue_scripts()

function navigation_script() {
    wp_register_script('admin-nav', get_stylesheet_directory_uri()  . '/js/admin-nav.js',array(), null, true);    
}
add_action( 'admin_enqueue_scripts', 'navigation_script' );
2

Right now your error is that you forgot to enqueue them,

function theme_enqueue_scripts(){
    wp_register_script('modernizr', get_stylesheet_directory_uri()  . '/js/modernizr.js');
    wp_register_script('require', get_stylesheet_directory_uri()  . '/js/vendor/requirejs/require.js', array(), false, true);
    wp_register_script('global', get_stylesheet_directory_uri()  . '/js/global.js', array('require'), false, true);      
    wp_register_style('globalstyle', get_stylesheet_directory_uri()  . '/css/global.css');

    wp_enqueue_script( array('modernizr','require','global') );
    wp_enqueue_style ('globalstyle');
}
add_action('wp_enqueue_scripts', 'theme_enqueue_scripts');

function navigation_script() {
    wp_register_script('admin-nav', get_stylesheet_directory_uri()  . '/js/admin-nav.js',array(), null, true);

    wp_enqueue_script('admin-nav');
}
add_action( 'admin_enqueue_scripts', 'navigation_script' );
2
  • Thanks, it worked. I removed wp_enqueue_script in the process of trial & error, and now after adding it back, it didn't work at first, but then it turned out that somebody from my team removed wp_footer() from footer.php :/ Oh well... Thanks a lot though – Karim Jun 12 '14 at 17:29
  • 1
    @Karim you don't have to register and enqueue a script. If you are not enqueueing conditionally, you can just enqueue your scripts/styles :) – Pieter Goosen Jun 12 '14 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.