Somewhere along the line I have messed up my js enqueue I am not sure how. I have the following in my functions.php file and I am including <?php wp_footer(); ?> in my footer.php before the js files were outputting in the footer no problem, but now it isn't working and I don't know why?

function foundationScripts() {
    if (!is_admin()) {

    wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js', false, '1.7.1',true);

  wp_enqueue_script('modernizr.js',get_template_directory_uri() . '/javascripts/modernizr.foundation.js',false,false,true); // for some reason this adds extra quotation marks in the body
  wp_enqueue_script('foundation.js',get_template_directory_uri() . '/javascripts/foundation.js',false,false,true);
  wp_enqueue_script('app.js',get_template_directory_uri() . '/javascripts/appF.js',false,false,true);

add_action('init', 'foundationScripts');

I am not sure if you posted code as-is or extracted part of it, but per this snippet - you are hooking function inside itself. Which doesn't seem like it will work nicely. :)

Also init hook should not be used for enqueue, on front-end hook to use is wp_enqueue_scripts, see where is the right place to register/enqueue scripts & styles.

Example functions.php code (assuming foundation is prefix you are using?):

add_action( 'after_setup_theme', 'foundation_after_setup_theme' );

function foundation_after_setup_theme() {

    add_action( 'wp_enqueue_scripts', 'foundation_wp_enqueue_scripts' );

function foundation_wp_enqueue_scripts() {

    // enqueues go here
  • +1 for noticing wp_enqueue_scripts missing. – SickHippie Mar 15 '12 at 22:16
  • This is the code posted as. How should I modify the functions code exactly. Do I just get rid if init and add wp_enqueue_scripts to my footer. – Anders Kitson Mar 15 '12 at 22:29
  • @Anders Kitson You should change to and move add_action('wp_enqueue_scripts', 'foundationScripts'); line outside of this function (and even better practice is dedicated initialization routine, hooked to after_setup_theme). – Rarst Mar 15 '12 at 22:31
  • @Rarst sorry I don't know what you mean by hooked to after_setup_theme. What I did was delete the function and placed wp_enqueu_scripts in my footer.php file and it works now, is that the wrong thing to do. – Anders Kitson Mar 15 '12 at 22:35

add_action needs to be outside the original function. Right now, it's in the function outside the if (!is_admin()) function.

Edit: As Rarst pointed out, you also need to use wp_enqueue_scripts instead of init.

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.