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

WordPress

Matt Campbell
Matt Campbell
9,767 Points

home_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
Kevin Korte
28,149 Points

Try throwing an echo statement in there.

This is correct, check the Codex: http://codex.wordpress.org/Function_Reference/home_url

Matt Campbell
Matt Campbell
9,767 Points

Bingo...shoulda read the codex properly.

Kevin Korte
Kevin Korte
28,149 Points

It 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
Matt Campbell
9,767 Points

Echo 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.