Both functions return the website url.

And, as home_url() needs sanitization (for example <?php echo esc_url( home_url( "https://wordpress.stackexchange.com/" ) ); ?>), why it is this snippet of code, instead of <?php echo get_ home_url( "https://wordpress.stackexchange.com/" ); ?>, that we found in WordPress Codex and WordPress Template Twenty Nineteen ?

2 Answers
2

There isn’t much difference but they are not the same.

get_home_url

get_home_url() takes null or a blog id as the first parameter. As per documentation here.

get_home_url( int $blog_id = null, string $path=””, string|null $scheme = null )

If you are dealing with multiple homes (as in, say a multi-site set up) this might be useful.

home_url

home_url(), on the other hand, is less fussed about per blog settings and just wants the home URL. As per documentation here.

home_url( string $path=””, string|null $scheme = null )

It is the equivalent of calling get_home_url( null, $path, $scheme );. Most of the time, this is the function you want.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *