How to Hide Publishing Site Actions Menu Links

July 15 2010 104 comments

One of our clients requested us to customize SharePoint in a way that we needed to hide/replace SharePoint Site Actions menu’s New Page -link. Well, at first we thought that this is easy task to do, but it wasn’t – until we figured out how to do it.

We googled a little bit, and found this thread:
SharePoint – Hide items in ‘Site Actions’ menu

Unfortunately the thread didn’t give us an answer that we could use. Well, there is a one answer: customization of “_catalogs/masterpage/Editing Menu/CustomSiteActions.xml”. Usually, we do not want to touch this file. It’s something that is better to be left for a customer to customize. And in this case we wanted to include this new feature in our product. Modifying CustomSiteAction.xml in our product essentially makes that file our property, and that’s not what we wanted.

But before we go to details, let’s look how Microsoft implemented their customizations in their Publishing feature.

Usually we can use <CustomAction> and <HideCustomAction> to add and remove links and buttons from SharePoint GUI. But Microsoft decided not to eat their own dog food in publishing actions. Wrong decision, if you ask us. Their intention for doing it differently in this case, was probably because they wanted to give a possibility to modify actions with SharePoint Designer (and that’s why they added the CustomSiteAction.xml, and the others). I don’t have internal information about this, it’s just a guess. Microsoft’s implementation wasn’t right on the spot.

How then Microsoft does this?

First of all, it all starts from FEATURES\Publishing. In that folder, let’s look at SiteActionMenuCustomization.xml:

 Title="Publishing SiteActions Menu Customization"
 ControlAssembly="Microsoft.SharePoint.Publishing, ..."

This is all fine and standard way to do it in SharePoint. But this isn’t a single action. It’s a class that creates whole lot of them. And that’s why we can only hide them all (with PublishingSiteActionsMenuCustomizer). But we needed to hide only one of them, as stated earlier.

How does this PublishingSiteActionsMenuCustomizer -class work?

It’s hard coded in this sealed class that it reads a file called:


If you look at this file, you see that it’s a collection of Console Nodes. For example:


This file basically replicates CustomAction and HideCustomAction -tags, but in an obfuscated way. As you can see from the above XML, this particular console node replaces normal “MenuItem_CreatePage” action with different implementation. It kinda replaces “New Wiki Page” with “New Publishing Page”. It also changes the id (from “MenuItem_CreatePage” to “wsaCreatePage”). And that’s why hiding “MenuItem_CreatePage” hasn’t any effect. Hiding “wsaCreatePage” (with HideCustomAction) doens’t work either, because these are created thought code later in the page life cycle, and SharePoint doesn’t know anything about them.

The Solution

First we created a new Custom Action with a Feature, here is our Custom Action:

 Title="Publishing Site Actions Menu Customization"
 Description="Replaces New Page action with a more intelligent one. "

And in the code we did write this:

public class CreatePublishingPageCustomization : WebControl
    protected override void OnLoad(EventArgs e)
        var menu = ToolBarMenuButton.GetMenuControl(this);
        menu.MenuControl.PreRender += (o, args) =>
            var item = menu.GetMenuItem("wsaCreatePage");
            if (item == null) return;

Okay, that looks easy now, but trust me, we looked at many many possibilities before finally found it. We needed to use MenuControl.PreRender, because otherwise the “wsaCreatePage” wasn’t there yet. Microsoft adds their publishing actions at PreRender.

Please let us know, if you did found this useful!

Popularity: 5% [?]

104 comments to “How to Hide Publishing Site Actions Menu Links”

  1. Teespring says:

    Do you mind if I quote a couple of your articles
    as long as I provide credit and sources back to your site? My blog site is in the exact same area of interest as yours and my visitors would truly benefit from some of the information you
    provide here. Please let me know if this okay with
    you. Regards!

  2. Nice post. I learn some thing much harder on different blogs everyday. It will always be stimulating you just read content from other writers and employ a specific thing at their store. I’d opt to apply certain using the content on my own blog whether you don’t mind. Natually I’ll provide a link on your own web weblog. Many thanks sharing.

  3. I get similar messages from my comment form. I usually wait a few days. If I get the same exact message, I delete both. If not, I might check out what they have to offer.

  4. Cassandra D. Everhart says:

    Excellent! Your post has a bunch viewers. carpet cleaning Winter Garden

Leave a Reply