get_site_icon_url( int $size = 512, string $url = '', int $blog_id = 0 ): string
- Since
- 4.3.0
- Source
wp-includes/general-template.php:965
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
- Scaling
- Constant
- Instructions
- 20–43
- Plugin surface
- 1 hook
- Called by
- 9
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, depending on the branch taken. The body compiles to 45.
Third-party callbacks on 'get_site_icon_url' run inside this call, and their cost is not bounded by anything here.
9 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()called directly - hookthird-party callbacks
apply_filters()called directly - cacheobject cache
wp_cache_switch_to_blog()one call below get_site_icon_url() - serializeserialisation
maybe_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 · 12 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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 20–22 | is_multisite(), get_option(), apply_filters() |
| always | 22–24 | is_multisite(), get_option(), restore_current_blog(), apply_filters() |
is_multisite() && !empty($blog_id) | 27 | is_multisite(), get_current_blog_id(), get_option(), apply_filters() |
| always | 29–32 | is_multisite(), get_option(), wp_get_attachment_image_url(), apply_filters() |
is_multisite() && !empty($blog_id) | 29 | is_multisite(), get_current_blog_id(), get_option(), restore_current_blog(), apply_filters() |
| always | 31–34 | is_multisite(), get_option(), wp_get_attachment_image_url(), restore_current_blog(), apply_filters() |
is_multisite() && !empty($blog_id) | 31 | is_multisite(), get_current_blog_id(), switch_to_blog(), get_option(), apply_filters() |
is_multisite() && !empty($blog_id) | 33 | is_multisite(), get_current_blog_id(), switch_to_blog(), get_option(), restore_current_blog(), apply_filters() |
is_multisite() && !empty($blog_id) | 36–37 | is_multisite(), get_current_blog_id(), get_option(), wp_get_attachment_image_url(), apply_filters() |
is_multisite() && !empty($blog_id) | 38–39 | is_multisite(), get_current_blog_id(), get_option(), wp_get_attachment_image_url(), restore_current_blog(), apply_filters() |
is_multisite() && !empty($blog_id) | 40–41 | is_multisite(), get_current_blog_id(), switch_to_blog(), get_option(), wp_get_attachment_image_url(), apply_filters() |
is_multisite() && !empty($blog_id) | 42–43 | is_multisite(), get_current_blog_id(), switch_to_blog(), get_option(), wp_get_attachment_image_url(), restore_current_blog(), apply_filters() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 45 instructions, 20–43 executed per call, 6 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.
Hooks and filters fired · 1
One hook fires while get_site_icon_url() runs, in this order:
Uses · 7
- is_multisite()Determines whether Multisite is enabled.
- get_current_blog_id()Retrieves the current site ID.
- switch_to_blog()Switches the current blog.
- get_option()Retrieves an option value based on an option name.
- wp_get_attachment_image_url()Gets the URL of an image attachment.
- restore_current_blog()Restores the current blog, after calling switch_to_blog().
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 9
- WP_REST_Server::add_site_icon_to_index()Exposes the site icon through the WordPress REST API.
- atom_site_icon()Displays Site Icon in atom feeds.
- do_favicon()Displays the favicon.ico file content.
- has_site_icon()Determines whether the site has a Site Icon.
- rss2_site_icon()Displays Site Icon in RSS2.
- site_icon_url()Displays the Site Icon URL.
- the_embed_site_title()Prints the necessary markup for the site title in an embed template.
- wp_admin_bar_my_sites_menu()Adds the "My Sites/[Site Name]" menu and all submenus.
- wp_site_icon()Displays site icon meta tags.
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 ); } $url = wp_get_attachment_image_url( $site_icon_id, $size_data ); } 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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 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.