Search This Blog

Tuesday, March 24, 2015

Hide the SharePoint 2010 Ribbon without Modifying the Master Page


Ever wish you could hide the SharePoint 2010 Ribbon from visitors to your site who have no need of it? Want to reclaim that 50 to 100 pixel waste of screen real estate at the top of your page but don't have access to your site's Master page? Well, read on! 

In order to effectively hide the Ribbon from those who don't need it, the best option is to security trim the area in your site’s master page. However, not all site owners have access to SharePoint Designer or if they do, don’t have permissions to modify the master page. Still other owners / administrators may not want to hide the ribbon on every page but only on a select set of pages. The problem is easily managed using Cascading Style Sheets (CSS). 

To begin, create a CSS file containing the following lines (or add these lines to an existing custom CSS file if you’re already using one for your site):

/* Hide Ribbon */

#s4-ribbonrow {

display: none;

}
Save the file to your site's asset library. If you're not using one, now is a good time to create one. Save the URL to the file. Next, add a Content Editor Web Part to the page on which you want the Ribbon hidden. Edit the CEWP’s HTML source and add a link to your CSS file:
<link href="/sites/YourSite/YourLibrary/PageStyling.css" rel="stylesheet" type="text/css"/>
(Note: Using the relative URL as shown above versus the absolute URL that includes "http://" can save you some headaches in the future.)

Edit the CEWP's settings and change the chrome to none or set the “Hidden” property under “Layout” to true. If you're anal like me, do both. Once you save the link in the CEWP, voila! Your Ribbon has vanished! Problem solved!
Or is it? Now  YOU can’t see the ribbon either. What happens when you need to edit the page? If your site is standard out of the box SharePoint, you can’t access the Site Actions menu now! As a matter of fact, now that you’ve added this code, you can’t even do anything to the page other than edit existing web parts that don't have the title bar hidden! You can’t even undo what you just did because you can’t access the HTML source of your new CEWP! What are you going to do?!
First, you’re going to stop panicking! We’ve got this under control! If you have access to SharePoint Designer, open your site, locate the library where you stored your new CSS file and open that document. If you can’t use SPD, open the copy of your CSS file that you created on your desktop. Move the closing brace (*/) from the “Hide Ribbon” comment to the end of the line as shown below:
/* Hide Ribbon

#s4-ribbonrow {

display: none;

} */
If using SPD, save the file. If you had to modify the file on your desktop, upload the modified file to the library where you stored your original. What? You can’t access the Site Actions menu to get to the “View All Site Content” link and it’s not available on your Quick Launch? No worries. Replace everything past your site’s name in the URL with this “/_layouts/viewlsts.aspx” and hit enter.  
Once you’ve modified the CSS file as shown or uploaded your modified file to your assets library, refresh or reload the page. Voila! Your Ribbon reappears!
Now how are we going to allow administrators to see the ribbon and still hide it from users who only have read access? Again, the best way to do this would be security trimming the #s4-ribbonrow element, but you’re here because you can’t do that for whatever reason. Instead, we’re going to create another CSS file containing the following:
/* Show Ribbon  */

#s4-ribbonrow {

display: block!important;

             }
Name your new file “Admin.css” (or something else that helps you know what it is at a glance) and upload it to your assets library. Return to the page where you’re trying to hide the Ribbon from those pesky site visitors and put the page back into edit mode. Add another CEWP to the page. As with the first, edit the CEWP settings so the chrome is "None" and/or the “Hidden” property is true. Edit the CEWP’s HTML source and add the link to your new Admin.css file. Save your changes and voila! No, just kidding. We’ve got a few more steps. 

If you don’t know CSS, what we just did was tell the browser that we want to display the Ribbon after we told it in the previous file that we want to hide it. Why’d we do that? Are we losing it? Well, maybe, but that’s irrelevant. When a browser reads through a list of CSS styles, it applies them as it comes to them. Adding “!important” after “block” in our code tells the browser that no matter what other commands it sees regarding the display of the Ribbon, obey THIS one because it’s…you guessed it…IMPORTANT! So it doesn’t matter if you put the CEWP containing the Admin.css link before or after the CEWP containing the CSS that hides the ribbon, it’s going to display the Ribbon because this tag is marked “!important”.
Right. So now that you’re thoroughly confused, let’s continue. You now have two options. Again, if you’re anal like me, you can do both. For option one, since we’re in the properties of the CEWP containing the Admin.css link already (you’re still there, right?), we’ll jump down to the “Advanced” section and find “Targeted Audiences”. Here, you’ll enter the name of your administrative group (i.e. Site Owners) and any other group that you want to be able to see the Ribbon (i.e. Content Managers, etc). Save the properties and voila! Only those you designated will see the Ribbon!
For option two, save your page and visit your assets library. Find the Admin.css file and break inheritance on its permissions. Remove all groups other than your administrative group and any other groups you want to see the Ribbon (add them if you need to). Voila! Only those you designated will see the Ribbon! 

No comments:

Post a Comment