Which function is used to get the home URL in WordPress?
Use home_url(). It gives the address of the front of your site, and you can add a path to it:
Terminal output
$ wp eval 'echo home_url() . "\n" . home_url( "/contact/" ) . "\n" . site_url() . "\n" . get_bloginfo( "url" );'
http://example.com
http://example.com/contact/
http://example.com
http://example.com
home_url(): the address where visitors open the site.site_url(): the address where the WordPress core files are installed. It is different fromhome_url()only when WordPress is in a sub folder.get_bloginfo( 'url' ): same ashome_url().
Always use esc_url( home_url( '/' ) ) when you print it in HTML.
Learn more about the similar topics:
| Tutorials |
|---|
| WordPress Themes |
| WordPress Top Theme List |
| WordPress Theme Files and Functions |
| WordPress Template Hierarchy |
| WordPress Enqueue Scripts and Styles |
| WordPress Loop |
| WordPress WP_Query Class |