The gear icon in SharePoint Online is the key to a lot of functionality in SharePoint Online, like Site Content or the Site Settings. But sometimes the owner of a site wants to have this disabled. Because SharePoint is a web application, we can do a lot using JavaScript.

So the script to remove the gear icon can look like this:


// make the gear icon on the top right invisible for users, who do not have
// manage permissions for the web.
// the solutions assumes that jQuery is available

$(document).ready(function() {
	if (_spPageContextInfo.hasManageWebPermissions == false) {
		setInterval(function() {
			$("#O365_MainLink_Settings.o365cs-nav-item.o365cs-nav-button.o365cs-topnavText.ms-bgc-tdr-h.o365button").hide();
		}, 500);
	}
});

In the script we check, whether the user has the permission to manage the web. When not, the gear icon is removed.

To make this script available in all pages within a site collection we just need some PowerShell scripting that makes use of the PowerShell PnP extensions. This example will store the script file in a library called "Scripts" and is assuming that this library already exists.


Write-Host "Upload RemoveGearIcon.js"

$f = Add-PnPFile -Path .\RemoveGearIcon.js -Folder "scripts"

$site = Get-PnPSite
$fileUrl = $site.Url + "/Scripts/RemoveGearIcon.js"

Write-Host "Add JavaScript Link"

$jsLink = Get-PnPJavaScriptLink -Name "RemoveGearIcon" -Scope Site

if ($jsLink -ne $null)
{
	Remove-PnPJavaScriptLink -Identity "RemoveGearIcon" -Scope Site -Force
}

$link = Add-PnPJavaScriptLink -Name "RemoveGearIcon" -Url $fileUrl -Sequence 200 -Scope Site

That’s all. The result will look like this:

Advertisements