These snippets will get or return the site’s url that is set under General Settings of your WordPress website.

WordPress Address

The site_url() template tag retrieves the site url for the current site. Use this to get the “WordPress address” as defined in general settings.

Example

<?php
$url = site_url();
echo $url; //output http://www.example.com or http://www.example.com/wordpress
?>

Or with slash appended

<?php
$url = site_url('/');
echo $url; //output http://www.example.com/ or http://www.example.com/wordpress/
?>

Home Address

The home_url() template tag retrieves the home URL for the current site. Use this to get the “site address” as defined in general settings.

Example

<?php
$url = home_url();
echo $url; //output http://www.example.com or http://www.example.com/home
?>

Or with slash appended

<?php
$url = home_url('/');
echo $url; //output http://www.example.com/ or http://www.example.com/home/
?>

The get_bloginfo('url') will output the same value without a slash at the end.

Example

<?php
$url = get_bloginfo('url');
echo $url; //output http://www.example.com or http://www.example.com/home
?>