site_url( string $path = '', string $scheme = null )

Retrieves the URL for the current site where WordPress application files (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible.


Description Description

Returns the ‘site_url’ option with the appropriate protocol, ‘https’ if is_ssl() and ‘http’ otherwise. If $scheme is ‘http’ or ‘https’, is_ssl() is overridden.


Top ↑

Parameters Parameters

$path

(string) (Optional) Path relative to the site URL.

Default value: ''

$scheme

(string) (Optional) Scheme to give the site URL context. See set_url_scheme().

Default value: null


Top ↑

Return Return

(string) Site URL link with optional path appended.



Top ↑

Source Source

File: wp-includes/link-template.php

function site_url( $path = '', $scheme = null ) {
	return get_site_url( null, $path, $scheme );
}

Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Codex

    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/

  2. Skip to note 2 content
    Contributed by mirgcire

    The contributed example is unclear because it states that the result is one of two options, but no information is given to determine which option to expect. Are we to assume it is random, and therefore must filter out the spurious occurrences of “wordpress”?

You must log in before being able to contribute a note or feedback.