Skip to content

Commit 1c8f8ce

Browse files
authored
Provide all resolutions of website icons; remove duplicated icon metadata (#810)
1 parent 6a242ae commit 1c8f8ce

8 files changed

+90
-57
lines changed

assets/img/favicon-48x48.png

-2.2 KB
Binary file not shown.

assets/img/sunflower-180.png

9.75 KB
Loading

assets/img/sunflower-192.png

10.5 KB
Loading

assets/img/sunflower-270.png

15.2 KB
Loading

assets/img/sunflower.png

31 KB
Loading

assets/img/sunflower.svg

+64-46
Loading

functions/theme.php

+26-4
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,39 @@ function sunflower_theme_class() {
2121
* Change URL to site icon to sunflower as default.
2222
*
2323
* @param string $url Site icon URL.
24+
* @param string $size Size in pixel.
2425
*/
25-
function sunflower_get_site_icon_url_defaults( $url ) {
26+
function sunflower_get_site_icon_url_defaults( $url, $size ) {
27+
28+
$site_icon_id = (int) get_option( 'site_icon' );
29+
2630
// A custom site icon seems to be set. Keep it untouched.
27-
if ( filter_var( $url, FILTER_VALIDATE_URL ) ) {
31+
if ( $site_icon_id && filter_var( $url, FILTER_VALIDATE_URL ) ) {
2832
return $url;
2933
}
34+
35+
switch ( $size ) {
36+
case 32:
37+
$icon_url = sunflower_parent_or_child( 'assets/img/favicon.ico' );
38+
break;
39+
case 192:
40+
$icon_url = sunflower_parent_or_child( 'assets/img/sunflower-192.png' );
41+
break;
42+
case 180:
43+
$icon_url = sunflower_parent_or_child( 'assets/img/sunflower-180.png' );
44+
break;
45+
case 270:
46+
$icon_url = sunflower_parent_or_child( 'assets/img/sunflower-270.png' );
47+
break;
48+
default:
49+
$icon_url = sunflower_parent_or_child( 'assets/img/sunflower.png' );
50+
break;
51+
}
3052
// Set default site icon to sunflower.
31-
return sunflower_parent_or_child( 'assets/img/favicon.ico' );
53+
return $icon_url;
3254
}
3355

34-
// Add filter only, of terms of use are accepted.
56+
// Add filter only, if terms of use are accepted.
3557
$sunflower_options = get_option( 'sunflower_first_steps_options' );
3658
if ( ( $sunflower_options['sunflower_terms_of_use'] ?? false ) === 'checked' ) {
3759
add_filter( 'get_site_icon_url', 'sunflower_get_site_icon_url_defaults', 10, 3 );

header.php

-7
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@
1717
<meta charset="<?php bloginfo( 'charset' ); ?>">
1818
<meta name="viewport" content="width=device-width, initial-scale=1">
1919
<link rel="profile" href="https://gmpg.org/xfn/11">
20-
<?php
21-
$sunflower_options = get_option( 'sunflower_first_steps_options' );
22-
if ( ( $sunflower_options['sunflower_terms_of_use'] ?? false ) === 'checked' ) {
23-
printf( '<link rel="icon" href="%s" type="image/svg+xml" sizes="any">', esc_attr( sunflower_parent_or_child( 'assets/img/sunflower.svg' ) ) );
24-
printf( '<link rel="icon" href="%s" type="image/png" sizes="48x48">', esc_attr( sunflower_parent_or_child( 'assets/img/favicon-48x48.png' ) ) );
25-
}
26-
?>
2720
<?php
2821
get_template_part( 'template-parts/open-graph' );
2922
?>

0 commit comments

Comments
 (0)