Sharepoint - Change favicon without changing master page
Actually the AdditionalPageHead delegate control is the way to go. To keep things simple I've wrapped the below code into the ASCX, but it would be better suited in an assembly deployed to the GAC.
<%@ Control Language="C#" compilationMode="Always" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Import Namespace="Microsoft.SharePoint.WebControls" %>
<%
Response.Write("\n<link rel=\"shortcut icon\" href='/_catalogs/masterpage/favicon.ico' />");
Response.Write("\n<link rel=\"icon\" type=\"image/png\" href='/_catalogs/masterpage/favicon.png' />");
Response.Write("\n<link rel=\"apple-touch-icon\" href='/_catalogs/masterpage/icon-ipad.png' />");
%>
<script runat="server">
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
foreach (Control htmlHeadChildControl in Page.Header.Controls)
{
if (typeof(Microsoft.SharePoint.WebControls.SPShortcutIcon) == htmlHeadChildControl.GetType())
{
htmlHeadChildControl.Visible = false;
break;
}
}
}
</script>
The code is adding custom favicons for different browsers and hides the SharePoint default favicon. Works for me with SharePoint 2010 and 2013 for years.
For future reference for those who haven't worked with AdditionalPageHead delegate controls, wrap it into the usual feature.xml and elements.xml as described here:
How can I enable JavaScript on every page at a site level?
and here:
Adding multiple controls to AdditionalPageHead
and here:
Best way to add a control to a page without using the MasterPage or a web part?
you can change the default FAVICON.ICO in the layouts folder, but that will be for the whole farm
c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\IMAGES
Another option is to script it
(function() {
var link = document.createElement('link');
link.type = 'image/x-icon';
link.rel = 'shortcut icon';
link.href = 'http://www.stackoverflow.com/favicon.ico';
document.getElementsByTagName('head')[0].appendChild(link);
}());
https://stackoverflow.com/questions/260857/changing-website-favicon-dynamically
This should be possible using AdditionalPageHead
delegate control, That way we can avoid editing master Page.