Why doesn’t wp_enqueue_script() work when including a JavaScript file with TEMPLATEPATH?

I am trying to use tips from here to add my JS file.

I put the following in the functions.php of atahualpa theme I’ve got installed

Read More
function lektor_init() {
  if (true) {
    wp_enqueue_script('lektor',TEMPLATEPATH.'/js/synteza.js');
  }
}
add_action('init','lektor_init'); 

TEMPLATEPATH has been already used before in there, so I just adapted it.
But it doesn’t show up.

What did I do wrong?

Related posts

Leave a Reply

3 comments

  1. function parent_theme_name_scripts() {
        wp_enqueue_script( 'lektor', get_template_directory_uri() . '/js/synteza.js', array(), '1.0.0', true );
    }
    
    add_action( 'wp_enqueue_scripts', 'parent_theme_name_scripts' );
    

    Add to your parents themes functions file.

    However, if you’re adding scripts to a parent theme, create a child theme and add the script to the child themes functions file using get_stylesheet_directory_uri()

    add_action( 'wp_enqueue_scripts', 'child_theme_name_scripts' );
    function child_theme_name_scripts() {
            wp_enqueue_script( 'lektor', get_stylesheet_directory_uri() . '/js/synteza.js', array(), '1.0.0', true );
        }
    

    Use wp_enqueue_scripts rather than init.

  2. if you use child themes, “template_directory” would return the parent theme directory location.
    I use ‘CHILD_URL’ and ‘PARENT_URL’ if you just need to print print urls.