How to Change Favicon with JavaScript


This code comes in handy when you don’t have access to the head of the page and need to change the favicon.

(function() {
    var link = document.querySelector("link[rel*='icon']") || document.createElement('link');
    link.type = 'image/x-icon';
    link.rel = 'shortcut icon';
    link.href = 'https://yourdomain.com/favicon.ico';
    document.getElementsByTagName('head')[0].appendChild(link);
})();

 



Written by: Jake Lett
Jake Lett is a B2B marketing consultant with over 15 years of experience in the digital marketing industry. He specializes in SEO, HubSpot, and PPC campaign management. Jake has a proven track record of helping businesses increase their online visibility and drive more traffic, leads and sales. He is a Certified Google Ads Specialist and a Certified HubSpot Developer.

Topic:

Related posts

Tags:

Want to Get Email Updates of New Articles?

Join My Email Newsletter