get_site_icon_url() is a WordPress PHP function that retrieves the Site Icon URL for a specific blog or the current blog, with a fallback URL if no site icon is found.
Usage
$site_icon_url = get_site_icon_url($size, $url, $blog_id); // your custom code here return $site_icon_url;
Parameters
$size
(int) Optional: Size of the site icon in pixels. Default is 512.$url
(string) Optional: Fallback URL if no site icon is found. Default is an empty string (”).$blog_id
(int) Optional: ID of the blog to get the site icon for. Default is the current blog.
More information
See WordPress Developer Resources: get_site_icon_url()
Examples
Get Site Icon URL of the Current Blog
Retrieve the site icon URL for the current blog with a default size of 512 pixels.
$site_icon_url = get_site_icon_url(); echo 'Site Icon URL: ' . $site_icon_url;
Get Site Icon URL with Custom Size
Retrieve the site icon URL for the current blog with a custom size of 128 pixels.
$size = 128; $site_icon_url = get_site_icon_url($size); echo 'Site Icon URL (128px): ' . $site_icon_url;
Get Site Icon URL with Fallback Image
Retrieve the site icon URL for the current blog with a fallback image URL.
$fallback_url = 'https://example.com/fallback-image.png'; $site_icon_url = get_site_icon_url(512, $fallback_url); echo 'Site Icon URL: ' . $site_icon_url;
Get Site Icon URL for a Specific Blog
Retrieve the site icon URL for a specific blog with ID 2.
$blog_id = 2; $site_icon_url = get_site_icon_url(512, '', $blog_id); echo 'Site Icon URL (Blog ID 2): ' . $site_icon_url;
Get Site Icon URL with Custom Size and Fallback Image
Retrieve the site icon URL for the current blog with a custom size of 128 pixels and a fallback image URL.
$size = 128; $fallback_url = 'https://example.com/fallback-image.png'; $site_icon_url = get_site_icon_url($size, $fallback_url); echo 'Site Icon URL (128px): ' . $site_icon_url;