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:
/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'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.
Share Improve this question asked Apr 30, 2015 at 17:09 IYBITWCIYBITWC 31 silver badge5 bronze badges 1- I'd like to add, get_bloginfo( 'template_directory' ) seems to work fine. I'd like to use get_template_directory() instead. – IYBITWC Commented Apr 30, 2015 at 17:10
1 Answer
Reset to default 3get_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/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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745350714a4623813.html
评论列表(0条)