0

I'm currently developing a site locally in MAMP PRO. When I use get_template_directory() inside of the standard functions.php file, the site path gets output correctly. However, I have a separate enqueue.php file that I use to enqueue my scripts.

I'm using a require to include the enqueue.php file.

require get_template_directory() . '/inc/enqueue.php';

My issue begins inside of enqueue.php. Whenever I try to use get_template_directory(), instead of returning the correct site path, I keep getting the following output:

http://project.dev/Users/myuser/Sites/rouge-theme/wp-content/themes/rougeman/js/jquery-1.11.3.min.js?ver=4.2

I can't seem to figure out why the /Users path gets added to the URL when I'm not in the functions file.

Any help would be greatly appreciated.

  • I'd like to add, get_bloginfo( 'template_directory' ) seems to work fine. I'd like to use get_template_directory() instead. – IYBITWC Apr 30 '15 at 17:10
3

get_template_directory() returns a filesystem path-- that is, it returns the path to the file as it would appear if you were browsing it on the local machine via a file browser.

Return Values

(string) Absolute path to the directory of the current theme (without the trailing slash).

https://codex.wordpress.org/Function_Reference/get_template_directory

That is what you are seeing. The function works correctly (based on my interpretation of your question, anyway).

You want get_template_directory_uri() instead, which will give you a path relative to your web server root and which is what get_bloginfo('template_directory'); gives you.

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.