Sometimes it is necessary to have the hyperlink of the logo on the top left link to the root site of our site collection. With a little JavaScript and the PowerShell PnP extensions, this task is pretty easy.

First we need a simple JavaScript that does the modifications, when the page was loaded. We are using jQuery in this case.


$(document).ready(function() {
	$(".ms-siteicon-a").attr("href", _spPageContextInfo.siteServerRelativeUrl);
});

Next we have to upload the script file to the root site of our site collection. And when the file was uploaded, we register a JavaScript link with a site scope. For this task we use the PowerShell PnP extensions.


Add-PnPFile -Path C:\Temp\RewriteLogoHref.js -Folder "SiteAssets/js"

Add-PnPJavaScriptLink -Name "RewriteLogoHref" -Url https://{your-tenant}.sharepoint.com/sites/{your-site}/SiteAssets/js/RewriteLogoHref.js -Scope Site

That’s it. In each subsite we can navigate to the root site of our site collection by clicking the site logo.

Advertisements