WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/site url

Contents

Description

The site_url template tag retrieves the site url for the current site (where the WordPress core files reside) with the appropriate protocol, 'https' if is_ssl() and 'http' otherwise. If scheme is 'http' or 'https', is_ssl() is overridden. Use this to get the "WordPress address" as defined in general settings. Use home_url() to get the "site address" as defined in general settings.

In case of WordPress Network setup, use network_site_url() instead.

Usage

<?php site_url$path$scheme ); ?>

Default Usage

<?php echo site_url(); ?>

Parameters

$path
(string) (optional) Path to be appended to the site url.
Default: None
$scheme
(string) (optional) Context for the protocol for the url returned. Setting $scheme will override the default context. Allowed values are 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
Default: null

Return

(string) 
Site url link with optional path appended.

Examples

$url = site_url();
echo $url;

Output: http://www.example.com or http://www.example.com/wordpress

(Note the lack of a trailing slash)

$url = site_url('/secrets/', 'https');
echo $url;

Output: https://www.example.com/secrets/ or https://www.example.com/wordpress/secrets/

Notes

Changelog

Source Code

site_url() is located in wp-includes/link-template.php.

Related

WordPress Directories:
home_url() Home URL http://www.example.com
site_url() Site directory URL http://www.example.com or http://www.example.com/wordpress
admin_url() Admin directory URL http://www.example.com/wp-admin
includes_url() Includes directory URL http://www.example.com/wp-includes
content_url() Content directory URL http://www.example.com/wp-content
plugins_url() Plugins directory URL http://www.example.com/wp-content/plugins
theme_url() Themes directory URL (#18302) http://www.example.com/wp-content/themes
wp_upload_dir() Upload directory URL (returns an array) http://www.example.com/wp-content/uploads
See also index of Function Reference and index of Template Tags.