The has_site_icon() WordPress PHP function determines whether the site has a Site Icon.
Usage
has_site_icon( $blog_id );
Example:
Input:
if ( has_site_icon() ) { echo 'This site has a site icon.'; } else { echo 'This site does not have a site icon.'; }
Output:
This site has a site icon.
or This site does not have a site icon.
Parameters
$blog_id
(int, optional) – ID of the blog in question. Default is the current blog.
More information
See WordPress Developer Resources: has_site_icon()
Examples
Check if the current site has a site icon
This example checks if the current site has a site icon and displays a message accordingly.
if ( has_site_icon() ) { echo 'This site has a site icon.'; } else { echo 'This site does not have a site icon.'; }
Check if a specific site has a site icon
This example checks if a specific site (with ID 2) has a site icon and displays a message accordingly.
$blog_id = 2; if ( has_site_icon( $blog_id ) ) { echo "Site $blog_id has a site icon."; } else { echo "Site $blog_id does not have a site icon."; }
Display site icon URL if available
This example checks if the current site has a site icon and displays the site icon URL if available.
if ( has_site_icon() ) { echo 'Site icon URL: ' . get_site_icon_url(); }
Display a default site icon if not available
This example checks if the current site has a site icon, and if not, it displays a default site icon.
if ( has_site_icon() ) { $site_icon_url = get_site_icon_url(); } else { $site_icon_url = 'https://example.com/default-icon.png'; } echo '<img src="' . $site_icon_url . '" alt="Site Icon">';
Display site icon for a specific site in a multisite installation
This example checks if a specific site (with ID 2) in a multisite installation has a site icon and displays it if available.
$blog_id = 2; if ( has_site_icon( $blog_id ) ) { $site_icon_url = get_site_icon_url( 0, '', $blog_id ); echo '<img src="' . $site_icon_url . '" alt="Site Icon">'; }