wp_site_icon()
Outputs the meta tag for the site icon: <link rel="icon" href="%s" sizes="32x32" />
Outputs 4 meta tags for different devices:
<link rel="icon" href="%s" sizes="32x32" /> <link rel="icon" href="%s" sizes="192x192" /> <link rel="apple-touch-icon-precomposed" href="%s"> <meta name="msapplication-TileImage" content="%s">
The function is used in the default WP filter, since version 4.3:
add_action( 'wp_head', 'wp_site_icon', 99 );
Before outputting the code, the function checks whether an icon is set for the site. The check for whether there is an icon or not essentially comes down to checking whether there is an option or not...
The attachment ID of the site icon is stored in the option 'site_icon':
// for MU $site_icon_id = get_blog_option( $blog_id, 'site_icon' ); // regular installation $site_icon_id = get_option( 'site_icon' );
See HTML5 link icon specification: https://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#rel-icon.
Hooks from the function
Returns
null. Outputs HTML code.
{{Usage}}
Examples
#1 Demo
Suppose we set the icon for the site in: Appearance > Customize > Site Identity, then the following code will work like this:
wp_site_icon(); /* will output: <link rel="icon" href="http://example.com/wp-content/uploads/2015/07/cropped-gorchitca___-32x32.jpg" sizes="32x32" /> <link rel="icon" href="http://example.com/wp-content/uploads/2015/07/cropped-gorchitca___-192x192.jpg" sizes="192x192" /> <link rel="apple-touch-icon-precomposed" href="http://example.com/wp-content/uploads/2015/07/cropped-gorchitca___-180x180.jpg"> <meta name="msapplication-TileImage" content="http://example.com/wp-content/uploads/2015/07/cropped-gorchitca___-270x270.jpg"> */
#2 Disable the output of the site icon, if it is installed
To do this, we need write following code in the themes functions.php file:
remove_action( 'wp_head', 'wp_site_icon', 99 );
Changelog
| Since 4.3.0 | Introduced. |