0

I want to load specific javascript files onto any page that uses the template hello-world.php below is the code that I have used to target the page, register and enqueue scripts. But for some unknown reason it wont enqueue the scripts. Any idea why?

Functions.php

function my_enqueue_wow() {
  if ( is_page_template( 'hello-world.php' ) ) {
        wp_register_script( 'js-wow', get_template_directory_uri() . '/assets/js/wow.min.js');
        wp_enqueue_script( 'js-wow', get_template_directory_uri() . '/assets/js/wow.min.js');
  }
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_wow' );
  • Do you have a proper Page Template called hello-world.php? – s_ha_dum Nov 2 '15 at 18:28
  • I believe is_page and is_page_template are not available inside functions.php – gdaniel Nov 2 '15 at 22:21
  • Is your template in a subdirectory? – czerspalace Nov 3 '15 at 8:25
  • @czerspalace yes it is in a subdirectory. @s_ha_dum I used a comment like this: <?php /* Template Name: Example Template */ ?> – Simon Nov 3 '15 at 11:10
  • 2
    Try adding the subdirectory name to your template name, like is_page_template( 'mydirectory/hello-world.php' ) per codex.wordpress.org/Function_Reference/… – czerspalace Nov 3 '15 at 17:41

Your Answer

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

Browse other questions tagged or ask your own question.