Using WordPress ‘get_site_icon_url()’ PHP function

The get_site_icon_url() WordPress PHP function returns the URL of the site icon.

Usage

get_site_icon_url($size, $url, $blog_id)

Example:

Input: get_site_icon_url(64, 'https://example.com/default-icon.png', 2)

Output: 'https://yourwebsite.com/site-icon.png'

Parameters

  • $size (int) Optional: Size of the site icon. Default is 512 (pixels).
  • $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

Display site icon in an <img> tag

Display the site icon with a size of 64 pixels and a fallback URL.

$site_icon_url = get_site_icon_url(64, 'https://example.com/default-icon.png');
echo '<img src="' . esc_url($site_icon_url) . '" alt="Site Icon" />';

Set site icon as favicon in a theme

Set the site icon as a favicon in the header.php file of your WordPress theme.

$site_icon_url = get_site_icon_url(32);
echo '<link rel="icon" href="' . esc_url($site_icon_url) . '" />';

Display site icon URL in a meta tag

Display the site icon URL in a meta tag for social media sharing.

$site_icon_url = get_site_icon_url(120);
echo '<meta property="og:image" content="' . esc_url($site_icon_url) . '" />';

Display site icon for a specific blog in a multisite installation

Display the site icon URL for a specific blog (with ID 3) in a multisite installation.

$site_icon_url = get_site_icon_url(64, 'https://example.com/default-icon.png', 3);
echo '<img src="' . esc_url($site_icon_url) . '" alt="Site Icon" />';

Display site icon URL with custom fallback

Display the site icon URL with a custom fallback URL if no site icon is set.

$fallback_icon_url = get_template_directory_uri() . '/images/default-icon.png';
$site_icon_url = get_site_icon_url(64, $fallback_icon_url);
echo '<img src="' . esc_url($site_icon_url) . '" alt="Site Icon" />';