I have some js which, rather than register and enqueue, I add directly to a page template.

Currently located outside of WP, I use

<script type="text/javascript" src="/apps/js/amplitude/amplitude.js"></script>

If I move it to a js folder inside my theme, how do I then include it in a template without hardcoding a root-relative path... can I use something like get_template_directory_uri?

1 Answer 1


Yes, you can use get_template_directory_uri to refer to the theme root path.

<script type="text/javascript" src="<?php echo get_template_directory_uri();?>/js/amplitude/amplitude.js"></script>

But prefered way of doing is to use wp_enqueue_script().

  • Thanks. I usually register/enqueue, but this adds extra flexibility (and is useful for quick tests of new js).
    – glvr
    Oct 31, 2016 at 11:33

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.