site_url( string $path = '', string|null $scheme = null ): string
- Since
- 3.0.0
- Source
wp-includes/link-template.php:3505
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.
Compatibility
- WordPress
- since 3.0.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$pathstringoptional- Path relative to the site URL. Default empty.Default:
'' $schemestring|nulloptional- Scheme to give the site URL context. See set_url_scheme().Default:
null
Return value
string- Site URL link with optional path appended.
Performance profile
How much work a call to site_url() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Moderate
- Scaling
- Constant
- Instructions
- 8
- Plugin surface
- None
- Called by
- 30
Reads stored settings via get_option(), cached per request but not free on a cold cache.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5. The body compiles to 8.
Nothing here hands control to plugin code.
30 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- optionoption read or write
get_option()one call below site_url() - hookthird-party callbacks
apply_filters()one call below site_url()
Further down the call graph this can also reach cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost site_url() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 8 | get_site_url() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 8 instructions, 8 executed per call, 0 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 1
- get_site_url()Retrieves the URL for a given site where WordPress application files (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible.
Used by · 30
- WP_Rewrite::mod_rewrite_rules()Retrieves mod_rewrite-formatted rewrite rules to write to .htaccess.
- WP_Site_Health::can_perform_loopback()Runs a loopback test on the site.
- WP_Widget_RSS::widget()Outputs the content for the current RSS widget instance.
- comment_form()Outputs a complete commenting form for use within a template.
- do_robots()Displays the default robots.txt file content.
- get_bloginfo()Retrieves information about the current site.
- get_the_password_form()Retrieves protected post password form content.
- get_theme_root_uri()Retrieves URI for themes directory.
- includes_url()Retrieves the URL to the includes directory.
- load_script_textdomain()Loads the script translated strings.
- network_site_url()Retrieves the site URL for the current network.
- newblog_notify_siteadmin()Notifies the network admin that a new site has been activated.
Show all 30
- render_block_core_rss()Renders the `core/rss` block on server.
- rsd_link()Displays the link to the Really Simple Discovery service endpoint.
- spawn_cron()Sends a request to run cron through HTTP request that doesn't halt page loading.
- translate_smiley()Converts one smiley code to the icon graphic file equivalent.
- twenty_twenty_one_password_form()Retrieve protected post password form content.
- wp_default_scripts()Registers all WordPress scripts.
- wp_default_styles()Assigns default styles to $styles object.
- wp_is_local_html_output()Checks whether a given HTML string is likely an output from this WordPress site.
- wp_login_form()Provides a simple login form for use anywhere within WordPress.
- wp_login_url()Retrieves the login URL.
- wp_logout_url()Retrieves the logout URL.
- wp_print_request_filesystem_credentials_modal()Prints the filesystem credentials modal when needed.
- wp_redirect_admin_locations()Redirects a variety of shorthand URLs to the admin.
- wp_registration_url()Returns the URL that allows the user to register on the site.
- wp_should_replace_insecure_home_url()Checks whether WordPress should replace old HTTP URLs to the site with their HTTPS counterpart.
- wp_xmlrpc_server::blogger_getUsersBlogs()Retrieves blogs that user owns.
- wp_xmlrpc_server::wp_getUsersBlogs()Retrieves the blogs of the user.
- wpmu_signup_user_notification()Sends a confirmation request email to a user when they sign up for a new user account (without signing up for a site at the same time). The user account will not become active until the confirmation link is clicked.
Source code
function site_url( $path = '', $scheme = null ) { return get_site_url( null, $path, $scheme );}Changelog
Introduced in 3.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-includes/link-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.