SharePoint Developer Support Team Blog

The Official blog of the SharePoint Developer Support Team

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

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

  • Comments 5
  • Likes

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="http://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="http://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
  • Did you mean to add the same module MasterPage to the MySiteFarmStapler or was it supposed to be the new ML_ApplyCustomMasterPageStapler instead?

  • 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????

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

  • Hi

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

  • How to change the master page of mysite in the Office 365?

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment