1

On a SP2016 on-premise farm, I am editing a HTML Master page. I want to hide the gear icon from everyone beside the site admin. In my previous experience in older version, I can modify the Master page, wrap the gear icon part with something like "<SharePoint:SPSecurityTrimmedControl runat=”server” Permissions=”ManageSubWebs”>".

However in the HTML Master page I cannot find anything like SharePoint:MenuItemTemplate. In the paired Master page, I also cannot find it. I can find SharePoint:MenuItemTemplate in seattle.master. I cannot find it in seattle.html. When I try to modify any master page, SharePoint prompt "This file may not be moved, deleted, renamed, or otherwise edited."

What is the best practice to achieve my goal?

2 Answers 2

1

I am afraid, top suite bar cannot be controlled from master page. It is being rendered directly from content database. If you want to hide settings gear icon for non- SharePoint admins users you have to do it via custom javascript code.

You need to add javascript code on document.ready

What we would do is use default page context info attribute isSiteAdmin to check if user is side admin or not, if not use jquery to hide that particular gear icon.

// A $( document ).ready() block.
$( document ).ready(function() {
   if(!_spPageContextInfo.isSiteAdmin){
        $("#O365_MainLink_Settings").hide()
  }
});
6
  • I tried to put your script to Master page. The if part is working but obj $("#O365_MainLink_Settings") is not found/invalid. It seems $("#O365_MainLink_Settings") is not yet finish rendering before if is triggered. Do you have idea to work around it?
    – Mark L
    Jul 26, 2019 at 9:24
  • did you put code inside document.ready ? Jul 26, 2019 at 9:30
  • Actually I tried not to use JQuery but using jsom & css only. HEre is my code: if(!_spPageContextInfo.isSiteAdmin){document.getElementById("O365_MainLink_Settings").style.display = "none";}
    – Mark L
    Jul 26, 2019 at 9:39
  • by wrapping the function with _spBodyOnLoadFunctionNames.push("myfunction"); it is working! Thanks.
    – Mark L
    Jul 26, 2019 at 9:55
  • Glad it helped...please upvote and mark it as answer for other's reference. Jul 26, 2019 at 10:01
1

You'd need to create copy of the seattle.master and modify and use that as master page. SharePoint doesn't allow modifying the seattle.master as it generates it from the seattle.html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.