Client Side Override the Site Logo's link in an SharePoint Site

In SharePoint sites that have any kind of hierarchy of subwebs, it is frequently desirable to override the logo's link behavior to link back to the root of the site collection.   There's a bunch of guidance on how to do this by overriding the master page, but not much on how to do this client-side, to avoid MasterPage manipulation.   Here's a script that helps to do this:

//update site icon link, SP overrides any direct reassignment so you have to change the existing ID
//and then create a dummy element with the existing ID to avoid future JS errors.
//read old link id
var prevId = $("#DeltaSiteLogo > a").attr('id');
//change the id
$("#" + prevId).attr({
      'id':'CustomSiteLogo',
      'title': 'Employee Portal Home',
      'href':window.location.protocol + "//" + window.location.host
});
$("#DeltaSiteLogo > a").after("<a id='" + prevId + "' href='#' style='display:none'>Dummy</a>");

You'll need jQuery to do this and I'd recommend putting this into a file and then injecting via a SiteCollection scope custom action.   Here's the simplest way to do that:

https://github.com/SharePoint/PnP-PowerShell/blob/master/Documentation/Add-PnPCustomAction.md 

Comments

Unknown said…
There is good information in this website.

Click Here

Popular posts from this blog

Programmatically Update Page Layouts

Microsoft Virtualilzation Headaches

ERROR: Failed to create feature receiver...