wppaste
WordPress

get_site_icon_url( int $size = 512, string $url = '', int $blog_id = 0 ): string

Since
4.3.0
Source
wp-includes/general-template.php:1167
Returns the Site Icon URL.

Compatibility

WordPress
since 4.3.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

$sizeintoptional
Size of the site icon. Default 512 (pixels).Default: 512
$urlstringoptional
Fallback url if no site icon is found. Default empty.Default: ''
$blog_idintoptional
ID of the blog to get the site icon for. Default current blog.Default: 0

Return value

string
Site Icon URL.

Performance profile

How much work a call to get_site_icon_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

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
20–54

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 57.

Plugin surface
1 hook

Third-party callbacks on 'get_site_icon_url' run inside this call, and their cost is not bounded by anything here.

Called by
10

10 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • optionoption read or writeget_option()called directly
  • hookthird-party callbacksapply_filters()called directly
  • cacheobject cachewp_cache_switch_to_blog()one call below get_site_icon_url()
  • serializeserialisationmaybe_unserialize()one call below get_site_icon_url()

Further down the call graph this can also reach 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 · 24 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost get_site_icon_url() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always20–22is_multisite(), get_option(), apply_filters()
always22–24is_multisite(), get_option(), restore_current_blog(), apply_filters()
is_multisite() && !empty($blog_id)27is_multisite(), get_current_blog_id(), get_option(), apply_filters()
is_multisite() && !empty($blog_id)29is_multisite(), get_current_blog_id(), get_option(), restore_current_blog(), apply_filters()
always30–33is_multisite(), get_option(), wp_get_attachment_image_url(), apply_filters()
is_multisite() && !empty($blog_id)31is_multisite(), get_current_blog_id(), switch_to_blog(), get_option(), apply_filters()
always32–35is_multisite(), get_option(), wp_get_attachment_image_url(), restore_current_blog(), apply_filters()
is_multisite() && !empty($blog_id)33is_multisite(), get_current_blog_id(), switch_to_blog(), get_option(), restore_current_blog(), apply_filters()
!is_ssl()35–38is_multisite(), get_option(), wp_get_attachment_image_url(), is_ssl(), apply_filters()
is_multisite() && !empty($blog_id)37–38is_multisite(), get_current_blog_id(), get_option(), wp_get_attachment_image_url(), apply_filters()
!is_ssl()37–40is_multisite(), get_option(), wp_get_attachment_image_url(), is_ssl(), restore_current_blog(), apply_filters()
is_multisite() && !empty($blog_id)39–40is_multisite(), get_current_blog_id(), get_option(), wp_get_attachment_image_url(), restore_current_blog(), apply_filters()
12 further outcomes, up to 54 instructions
is_ssl()40–43is_multisite(), get_option(), wp_get_attachment_image_url(), is_ssl(), set_url_scheme(), apply_filters()
is_multisite() && !empty($blog_id)41–42is_multisite(), get_current_blog_id(), switch_to_blog(), get_option(), wp_get_attachment_image_url(), apply_filters()
is_multisite() && !empty($blog_id) && !is_ssl()42–43is_multisite(), get_current_blog_id(), get_option(), wp_get_attachment_image_url(), is_ssl(), apply_filters()
is_ssl()42–45is_multisite(), get_option(), wp_get_attachment_image_url(), is_ssl(), set_url_scheme(), restore_current_blog(), apply_filters()
is_multisite() && !empty($blog_id)43–44is_multisite(), get_current_blog_id(), switch_to_blog(), get_option(), wp_get_attachment_image_url(), restore_current_blog(), apply_filters()
is_multisite() && !empty($blog_id) && !is_ssl()44–45is_multisite(), get_current_blog_id(), get_option(), wp_get_attachment_image_url(), is_ssl(), restore_current_blog(), apply_filters()
is_multisite() && !empty($blog_id) && !is_ssl()46–47is_multisite(), get_current_blog_id(), switch_to_blog(), get_option(), wp_get_attachment_image_url(), is_ssl(), apply_filters()
is_multisite() && !empty($blog_id) && is_ssl()47–48is_multisite(), get_current_blog_id(), get_option(), wp_get_attachment_image_url(), is_ssl(), set_url_scheme(), apply_filters()
is_multisite() && !empty($blog_id) && !is_ssl()48–49is_multisite(), get_current_blog_id(), switch_to_blog(), get_option(), wp_get_attachment_image_url(), is_ssl(), restore_current_blog(), apply_filters()
is_multisite() && !empty($blog_id) && is_ssl()49–50is_multisite(), get_current_blog_id(), get_option(), wp_get_attachment_image_url(), is_ssl(), set_url_scheme(), restore_current_blog(), apply_filters()
is_multisite() && !empty($blog_id) && is_ssl()51–52is_multisite(), get_current_blog_id(), switch_to_blog(), get_option(), wp_get_attachment_image_url(), is_ssl(), set_url_scheme(), apply_filters()
is_multisite() && !empty($blog_id) && is_ssl()53–54is_multisite(), get_current_blog_id(), switch_to_blog(), get_option(), wp_get_attachment_image_url(), is_ssl(), set_url_scheme(), restore_current_blog(), apply_filters()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev5620–5381 fewer instruction than PHP 8.5
8.55720–548
8.45720–548
8.35720–548
8.25720–548
8.15720–548
7.45720–548

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.

Hooks and filters fired · 1

One hook fires while get_site_icon_url() runs, in this order:

  1. apply_filters( get_site_icon_url )filterline 1202 (+35 into the body)

    Filters the site icon URL.

Uses · 9

Used by · 10

Source code

function get_site_icon_url( $size = 512, $url = '', $blog_id = 0 ) {	$switched_blog = false; 	if ( is_multisite() && ! empty( $blog_id ) && get_current_blog_id() !== (int) $blog_id ) {		switch_to_blog( $blog_id );		$switched_blog = true;	} 	$site_icon_id = (int) get_option( 'site_icon' ); 	if ( $site_icon_id ) {		if ( $size >= 512 ) {			$size_data = 'full';		} else {			$size_data = array( $size, $size );		}		$attachment_url = wp_get_attachment_image_url( $site_icon_id, $size_data );		if ( $attachment_url ) {			$url = is_ssl() ? set_url_scheme( $attachment_url, 'https' ) : $attachment_url;		}	} 	if ( $switched_blog ) {		restore_current_blog();	} 	/**	 * Filters the site icon URL.	 *	 * @since 4.4.0	 *	 * @param string $url     Site icon URL.	 * @param int    $size    Size of the site icon.	 * @param int    $blog_id ID of the blog to get the site icon for.	 */	return apply_filters( 'get_site_icon_url', $url, $size, $blog_id );}

Changelog

Introduced in 4.3.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/general-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.