Hide Site Contents from Visitors in SharePoint 2019?
As you know, the SharePoint Visitors group has Read Permission by default, and to hide the Site Contents
option from the Site Setting List, you have to do the following:
- Open Site Collection > Click on the Settings Gear icon, then Click on
Site Settings
.
- Under
Users and Permissions
, Click on Site Permissions
.
- From the above ribbon, click on
Permission Levels
.
- Click on the
Read
Permission Level to edit it.
It's preferred to copy the Read permission level and create a new one with your new customization, then create a new group with the new permission level.
- Uncheck "View Application Pages - View forms, views, and application pages. Enumerate lists.", then click
Ok
.
- Try now to log in to your site with a user in the visitor's group, and you will note that the
Site Contents
is now removed based on the user permission.
See also How to Get SharePoint Folder Permissions Using JavaScript?
Hide Site Contents from Visitors in SharePoint using CSS?
If you want to provide the View Application Pages rights
to allow the user to view the InfoPath and other forms while also removing the Site Contents menu item, you have to do that using the CSS code below.
For the SharePoint classic experience, you can add the below CSS either to your master page to apply it on all sites or using script editor web part to apply it for specific page
<style>
span.ms-splinkbutton-text {
Display:none!important;
}
#sideNavBox a[href$="/_layouts/15/viewlsts.aspx"] {
display: none;
}
</style>
For SharePoint Online Modern Team sites, you can the below CSS to remove site contents:
<style>
.ms-Nav-navItem a[href$="/_layouts/15/viewlsts.aspx"] {
display: none;
}
</style>