none
How to remove or hide Site Actions items

    Question

  • Hello all,

    Is there any way to remove or hide Site Actions items from sharepoint site. You can see in the image, i want to remove either the complete Site Actions from ribbon or the specific items inside the Site Actions. How can i achive this ???, Thanks in advance.

     

    Wednesday, June 20, 2012 8:19 AM

Answers

  • Put the below code in master page,just above the </head> tag.

    Solution 1

    <style type="text/css">
    #siteactiontd{
    display:none;
    }
    </style>    

    <script type="text/javascript">  

    _spBodyOnLoadFunctionNames.push("ExecuteOrDelayUntilScriptLoaded(checkUser, 'sp.js')");

    </script>
    <script type="text/javascript">
    var currentUserId ;
    var vCurrUserName;
    function checkUser()
    {

         var currentContext = new SP.ClientContext();

        vCurrUserName= currentContext.get_web().get_currentUser(); 
        currentContext.load(vCurrUserName);

        currentContext.executeQueryAsync(Function.createDelegate(this, this.checkUserSuccess), Function.createDelegate(this, this.checkUserFailure));
    }


    function checkUserSuccess()
     {
    var currentUserId = vCurrUserName.get_id();
    if(currentUserId == 18)
    {
    document.getElementById("siteactiontd").style.display = "block";
    }
     } 


    function checkUserFailure()
     {
    //Failed to get user
     }
    </script>

    Solution 2

    <style type="text/css">
    #siteactiontd{
    display:none;
    }
    </style>

    <script type="text/javascript">
    _spBodyOnLoadFunctionNames.push("checkUser()");
    </script>

    <script type="text/javascript">
    function checkUser()
    {
    if(_spUserId == 18)
    {
    document.getElementById("siteactiontd").style.display = "block";
    }
    }


    Thanks, Neha Navale



    • Edited by NehaNavale Friday, June 22, 2012 10:27 AM
    • Marked as answer by Rauf Ab Monday, June 25, 2012 5:19 AM
    Friday, June 22, 2012 10:25 AM

All replies

  • If the user has read only permission then Site Action will not show.


    Jayant Sharma

    Wednesday, June 20, 2012 8:26 AM
  • You can use SPSecurityTrimmerdControl wrap around the SiteActions control in the master  page (This way only site  owners are able to see the site action menu)

    Also, you can refer this (Hiding Menu items by ID)

    http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/6fb5127b-41ca-4cdb-97f4-172795da4b26

    You can also do this by using Features. Refer this:

    http://www.sharepointblues.com/2010/07/15/how-to-hide-publishing-site-actions-menu-links/

    Wednesday, June 20, 2012 8:34 AM
  • To hide the Site Actions from all users explicitly, find the object with id "siteactiontd" and hide it.

    document.getElementById(“siteactiontd”).display = “none”;

    The above script must be called in master page

    Or can be done using CSS

    <style type="text/css">

    #siteactiontd{

    Display:none;

    }

    </style>


    Thanks, Neha Navale

    Wednesday, June 20, 2012 8:42 AM
  • Actually scenario is little bit different which i explain again.

    I am an administrator of sharepoint site, i have my co-administrator, we both have admin rights of site, I as a main administrator want to hide site actions from my co-administrator even she have full rights of the site. but not to myself as a main administrator.

    Now please share the workaround, thanks.

    Wednesday, June 20, 2012 9:49 AM
  • Add the following style in master page

    <style type="text/css">

    #siteactiontd{

    Display:none;

    }

    </style>

    The style will hide the Site Action from all

    Then add a code/script which will check, if you are the logged in user

    then show Site Action


    Thanks, Neha Navale

    Wednesday, June 20, 2012 9:56 AM
  • Neha thanks,

    I am really out of mind that how can i achieve which you suggested. How can i check login user in master page and how can i use if else to either hide or unhide from specific users, please help me little more to achive this, thanks.

    Wednesday, June 20, 2012 10:04 AM
  • <script type="text/javascript"> _spBodyOnLoadFunctionNames.push(ExecuteOrDelayUntilScriptLoaded(checkUser, "sp.js"); ); </script> <script type="text/javascript"> var currentUserId ;

    var vCurrUserName;

    function checkUser() { var currentContext = new SP.ClientContext(); vCurrUserName= currentContext.get_web().get_currentUser(); currentContext.load(vCurrUserName); currentContext.executeQueryAsync(Function.createDelegate(this, this.checkUserSuccess), Function.createDelegate(this, this.checkUserFailure)); } function checkUserSuccess() { var currentUserId = vCurrUserName.get_id(); if(currentUserId == "YourID") {

    document.getElementById(“siteactiontd”).display = “block”;
    	
    	}
     } 
    
    
    function checkUserFailure()
     {
     	//Failed to get user
     }
    </script>

    <style type="text/css">

    #siteactiontd{

    Display:none;

    }

    </style>

    Add the above script and style in master page


    Thanks, Neha Navale



    • Edited by NehaNavale Wednesday, June 20, 2012 10:48 AM
    Wednesday, June 20, 2012 10:44 AM
  • Thanks Neha,

    I tried your code but iam sorry i didn't successfull :(. I know this solution should work, Can you please tell me where to exactly put this code in master page ???. Iam really thankful for your detailed and comprehensive answer but iam not lucky becoz i could not properly implement, thanks.

    Thursday, June 21, 2012 5:48 AM
  • Hi,

    Below is the code which may help you to hide the site action from the admin. You just have to provide the admin name as shown below in the code.

    <asp:ContentPlaceHolder id="PlaceHolderTitleAreaClass" runat="server">
    <script type="text/javascript" src="../../SiteAssets/Scripts/jquery-1.6.4.js"></script>
    <script type="text/javascript" src="../../SiteAssets/Scripts/jquery.SPServices-0.6.2.js"></script>
    <script type="text/javascript">
    //Code to get the logged in user name

    $(document).ready(function() {

    var username =$().SPServices.SPGetCurrentUser({
    fieldName: "Title"
    });

    var tmpUser = "admin1"

    if(username.toLowerCase().trim()== tmpUser.toLowerCase().trim() )
    {

    document.getElementById("siteactiontd").style.display = "none";
    }
    });



    </script>
    </asp:ContentPlaceHolder>


    MCTS- Please mark posts as answered where appropriate.



    Thursday, June 21, 2012 12:38 PM
  • Neha will you please tell me that where can i exactly put your code in master page ???, I tried but it is not working, thanks.
    Friday, June 22, 2012 9:55 AM
  • You can put the code in head tag of master page. Just above the line </head>.



    Thanks, Neha Navale

    Friday, June 22, 2012 9:59 AM
  • if(currentUserId == "YourID")

    in the above line should i use Id in integer value or a user or a domain account like MYDOMIAN\mareena.arrora ???, thanks

    Friday, June 22, 2012 10:05 AM
  • use value like if(currentUserId == "18")

    Another solution I found is 

    function checkUser()
    {
    
    if(_spUserId == "18")
     {
     	document.getElementById(“siteactiontd”).display = “block”;
     }
    }

    _spUserId is JavaScript variable used by SharePoint scripts to store current user's ID

    So you will not need checkUserSuccess and checkUserFailure, just call checkUser as

    <script type="text/javascript">
    _spBodyOnLoadFunctionNames.push(checkUser());
    </script>

    Let me know, your feedback



    Thanks, Neha Navale

    Friday, June 22, 2012 10:12 AM
  • Put the below code in master page,just above the </head> tag.

    Solution 1

    <style type="text/css">
    #siteactiontd{
    display:none;
    }
    </style>    

    <script type="text/javascript">  

    _spBodyOnLoadFunctionNames.push("ExecuteOrDelayUntilScriptLoaded(checkUser, 'sp.js')");

    </script>
    <script type="text/javascript">
    var currentUserId ;
    var vCurrUserName;
    function checkUser()
    {

         var currentContext = new SP.ClientContext();

        vCurrUserName= currentContext.get_web().get_currentUser(); 
        currentContext.load(vCurrUserName);

        currentContext.executeQueryAsync(Function.createDelegate(this, this.checkUserSuccess), Function.createDelegate(this, this.checkUserFailure));
    }


    function checkUserSuccess()
     {
    var currentUserId = vCurrUserName.get_id();
    if(currentUserId == 18)
    {
    document.getElementById("siteactiontd").style.display = "block";
    }
     } 


    function checkUserFailure()
     {
    //Failed to get user
     }
    </script>

    Solution 2

    <style type="text/css">
    #siteactiontd{
    display:none;
    }
    </style>

    <script type="text/javascript">
    _spBodyOnLoadFunctionNames.push("checkUser()");
    </script>

    <script type="text/javascript">
    function checkUser()
    {
    if(_spUserId == 18)
    {
    document.getElementById("siteactiontd").style.display = "block";
    }
    }


    Thanks, Neha Navale



    • Edited by NehaNavale Friday, June 22, 2012 10:27 AM
    • Marked as answer by Rauf Ab Monday, June 25, 2012 5:19 AM
    Friday, June 22, 2012 10:25 AM
  • Thaks neha, i done it.
    Monday, June 25, 2012 5:19 AM