diff --git a/layouts/partials/favicon.html b/layouts/partials/favicon.html
index 0d6bbe3161..ffb20f71f2 100644
--- a/layouts/partials/favicon.html
+++ b/layouts/partials/favicon.html
@@ -1,26 +1,46 @@
{{- $assetBusting := not .Site.Params.disableAssetsBusting }}
- {{- if or (fileExists "/static/images/favicon-light.svg") (fileExists "/static/images/favicon-dark.svg") }}
+ {{- $faviconMatch := false }}
+ {{- $svg := dict "ext" "svg" "type" "image/svg+xml" }}
+ {{- $png := dict "ext" "png" "type" "image/png" }}
+ {{- $ico := dict "ext" "ico" "type" "image/x-icon" }}
+ {{- $faviconTypes := slice $svg $png $ico }}
+ {{- range $faviconTypes }}
+ {{- if and
+ (eq $faviconMatch false)
+ (or
+ (fileExists (printf "/static/images/favicon-light.%s" .ext))
+ (fileExists (printf "/static/images/favicon-dark.%s"))
+ )
+ }}
+ {{- $faviconMatch = true }}
{{/*
Warning: IE and old browser versions do not support media queries necessary for the light & dark theme option.
If you have requirements to support IE and/or older browser versions, use one of the other options.
Reference: https://caniuse.com/css-media-interaction
*/}}
- {{- if (fileExists "/static/images/favicon-light.svg") }}
-
+ {{- if (fileExists (printf "/static/images/favicon-light.%s" .ext)) }}
+
{{- end }}
- {{- if (fileExists "/static/images/favicon-dark.svg") }}
-
+ {{- if (fileExists (printf "/static/images/favicon-dark.%s" .ext)) }}
+
+ {{- end }}
+ {{- end }}
+ {{- end }}
+ {{- range $faviconTypes }}
+ {{- if and
+ (eq $faviconMatch false)
+ (fileExists (printf "/static/images/favicon.%s" .ext))
+ }}
+ {{- $faviconMatch = true }}
+
+ {{- end }}
+ {{- end }}
+ {{- range $faviconTypes }}
+ {{- if and
+ (eq $faviconMatch false)
+ (fileExists (printf "/static/images/logo.%s" .ext))
+ }}
+ {{- $faviconMatch := true }}
+
{{- end }}
- {{- else if (fileExists "/static/images/favicon.svg") }}
-
- {{- else if (fileExists "/static/images/favicon.png") }}
-
- {{- else if (fileExists "/static/images/favicon.ico") }}
-
- {{- else if (fileExists "/static/images/logo.svg") }}
-
- {{- else if (fileExists "/static/images/logo.png") }}
-
- {{- else if (fileExists "/static/images/logo.ico") }}
-
{{- end }}
\ No newline at end of file