Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
get_template_directory_uri 404 error
I'm following the course on here and am wondering if there would be any prefix to working locally on MAMP with a sub-folder.
I have the wpt files within a sub-folder in my htdocs and when I try to load the index.php the css & js does not load however the html does load.
When inspecting the DOM I get the following error.
http://localhost:8888/treehouseget_template_directory_uri/style.css?ver=4.7.3 Failed to load resource: the server responded with a status of 404 (Not Found)
Now, I see the error. There is no forward slash between treehouse and get_template_directory_uri
My question, is the resource path correct (I assume not) and is there anything extra I would have to put in the functions.php file to correct this.
I have done some digging on the usual internet pages but have found nothing on this.
Thanks for your reply. Regards, Sam.
Hey there, You're really close but there's one thing that's not quite right here:
get_template_directory_uri is actually a function in WordPress, so you have to add a set of parentheses after it. If you enqueue your stylesheet (in
functions.php) in the following way:
get_template_directory_uri() . '/style.css'
(or, if you are just hard-coding the stylesheet link into your site's
<head>, write it like this:)
<link rel="stylesheet" href="<?php echo get_template_directory_uri() . '/style.css'; ?>">
...then WordPress will run the
get_template_directory_uri function and return the entire file path to your
themes subfolder, which should make the entire path to the style.css file work.
Does that solve it for you? Let me know if you have any questions.