Freigeben über


HOW TO: Change master page of a personal site in SharePoint 2013

This post is a contribution from Pavan Kumar, an engineer with the SharePoint Developer Support team.

As in SharePoint 2007 and 2010, one of the ways to achieve this is to use FeatureStapling. Below are the steps to be followed to get this working.

Create a SharePoint 2013 Empty project in Visual Studio 2012 and give it a name (e.g., ChangeMySiteMaster).

image

Provide your MySite Host URL and choose to deploy this as a farm solution.

image

Add a new Module from Visual Studio 2012 SharePoint item templates to the project.

image

By default, MySites use mysite15.master as its default master page.  This can be found under 15\TEMPLATE\FEATURES\MySiteMaster\mysite15.master.  Copy this file and add it to the project you created.  Rename it to CustomMySite.master and modify this file per your needs.

Delete Sample.txt available in the Module and edit Elements.xml file such that it looks like this:

 <?xml version="1.0" encoding="utf-8"?>
 <Elements xmlns="https://schemas.microsoft.com/sharepoint/">
   <Module Name="MasterPage" List="116" Url="_catalogs/masterpage" Path="MasterPage" RootWebOnly="TRUE">
     <File Url="CustomMySite.master" Type="GhostableInLibrary"/>
   </Module>
 </Elements>

Add a new feature to the project and add a feature event receiver to it.  Ensure that module is added to the feature.

image

image

Add below code in FeatureActivated event of EventReceiver.cs.

image

Add below code in FeatureDeactivating event of EventReceiver.cs.

image

Create another farm level feature.  Name it as MySiteFarmStapler.  Add a new empty element to the project and name it as ML_ApplyCustomMasterPageStapler.  Add the following markup to the XML.

 <?xml version="1.0" encoding="utf-8"?>
 <Elements xmlns="https://schemas.microsoft.com/sharepoint/">
   <FeatureSiteTemplateAssociation Id=<GUID from EventReceiver.cs>" TemplateName="SPSPERS" />
 </Elements>

Add the module to Stapler feature.

image

Save all the files and deploy.  Login to your personal site and activate the feature from Site collection features.  Personal sites created henceforth will have the new master page applied to it.

Comments

  • Anonymous
    November 23, 2013
    Did you mean to add the same module MasterPage to the MySiteFarmStapler or was it supposed to be the new ML_ApplyCustomMasterPageStapler instead?

  • Anonymous
    June 06, 2014
    Dito,,, what Travis said. It is not clear which module to add to the last feature? The flow of the instructions would mean the last element module but the picture shows the Masterpage module????

  • Anonymous
    July 01, 2014
    Can you please respond to us? This is a topic with a lot of discussion and clearer directions would be awesome!

  • Anonymous
    August 07, 2014
    Hi

    If there is any change in master page, do we need to redeploy everything?

  • Anonymous
    September 18, 2014
    How to change the master page of mysite in the Office 365?

  • Anonymous
    December 11, 2014
    Hi all - for those who could not complete this follow instructions at http://sharepointologic.blogspot.com.au/2013/04/branding-sharepoint-2013-my-sites-with.html
    I could deploy it successfully as it is very clearer there

  • Anonymous
    March 18, 2015
    The comment has been removed