Subpage- or Theme-Specific Favicons
I already have a functional general favicon for my site (via the “Settings” > “Favicon” interface). However, I would like to add two additional favicon-related functionalities to my site:
- A “dark mode” favicon for display on dark-mode browser themes.
- A special subpage favicon (for a specific subpage)
So far, I attempted to add such functionalities through a custom <link>
element (with absolute URLs) in the head section of relevant pages via “Settings” > " Development & integrations" > “Custom Code”. The code appears in the <head>
of my published page (I checked via Inspect Element), but does not actually render the contextual favicon (in Chrome at least)
Here’s an example for a “dark mode” favicon with a “media” attribute:
<link rel="icon" sizes="192x192" media="(prefers-color-scheme: dark)" href="https://static.wixstatic.com/media/randomstring.png" type="image/png" />
Notably, my <link>
occurs in the <head>
section after the default Wix favicon <link>
, so perhaps the browsers ignore the subsequent <link>
elements.
Additionally, I attempted to get a custom subpage favicon with JavaScript, using both header custom code and masterPage.js
document.querySelectorAll('link[href*="https://static.wixstatic.com/media/RandomString1.png"]');
Array.prototype.forEach.call(function (element, index) {
element.href = "https://static.wixstatic.com/media/RandomString2.png";
});
However, from my understanding, Wix does not recognize “document.querySelectorAll” to prevent unstable meddling with the section.
Are there any alternative methods or workarounds? There seems to be limited documentation for favicons, besides the singular generic favicon setting. I’m happy to play around with various CSS, HTML, and JS options within the various Wix editing environments, if anyone has ideas/suggestions.