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 trialMatt Campbell
9,767 Pointshome_url() doesn't work locally.
Just wandering why home_url() won't work when developing locally on Xampp.
Is it a setting I've got wrong or is this the general case for using home_url locally.
You'll probably know Zac Gordon. :)
3 Answers
Kevin Korte
28,149 PointsTry throwing an echo statement in there.
Kevin Korte
28,149 PointsIt works on my WP site using Xampp.
What happens when you throw this code into your theme and visit that page? Do you get any output?
<?php
$url = home_url();
echo $url;
?>
Matt Campbell
9,767 PointsEcho it out as a variable like you've done on the homepage, proper url. http://localhost/thecitymembersclub
Echo it out as a variable in the functions file I want to use it, proper url. http://localhost/thecitymembersclub
Use it like this:
onClick="location.href='<?php home_url(); ?>/wp-login.php?action=register'"
Spits out this http://localhost/wp-login.php?action=register instead of http://localhost/thecitymembersclub/wp-login.php?action=register
Don't get it. Soon as I put the site online though, it'll work.
Paul Graham
1,396 PointsPaul Graham
1,396 PointsThis is correct, check the Codex: http://codex.wordpress.org/Function_Reference/home_url
Matt Campbell
9,767 PointsMatt Campbell
9,767 PointsBingo...shoulda read the codex properly.