include script that depends on modernizr?

first time i am trying to include script to wordpress,but
after several hours reading wordpress codex and answers all over the web ,i still dont success to link the script to modernizr,
they both show in the head of the page as if they were registerd correctly but the script still ignores modernizr.

here is the code in function.php

function childtheme_script_manager() {
wp_register_script('new_service', get_template_directory_uri() .'/js/modernizr.custom.79639.js', array('jquery'), true, true);
wp_enqueue_script('new_service');
}

add_action('wp_enqueue_scripts', 'childtheme_script_manager');

function twentyfourteen_child_scripts() {
     wp_enqueue_script('twentyfourteen_child_scripts',   get_template_directory_uri().'/js/jquery.swatchbook.js');
}

add_action( 'wp_enqueue_scripts', 'twentyfourteen_child_scripts' );

Related posts

1 comment

  1. I assume these are child theme scripts because of your function name:

    twentyfourteen_child_scripts()
    

    When loading scripts from your child themes functions file you should use:

    wp_enqueue_script( '$handle', get_bloginfo( 'stylesheet_directory' ) . '/js/filename.js', array( 'jquery' ), '1.0.0' );
    

    Or use

    add_action( 'wp_enqueue_scripts', 'child_add_modernizr_scripts' );
    
    function child_add_modernizr_scripts() {
    wp_register_script('modernizr', get_stylesheet_directory_uri() . '/js/modernizr.js', false, '1.0', true );
    
    wp_enqueue_script( 'modernizr' );
    }
    

    Another potential problem maybe the file names are invalid for some reason.

    get_template_directory_uri()
    

    Applies to parent themes.

Comments are closed.