Make your custom theme a default theme for present site and it’s sub-sites.

Following images show the OOB site themes :-

clip_image002

Suppose if would like to apply a new site theme when a site or sub-site is created then you need to follow the following steps:-

1. Create a new feature and set the scope as “ApplyMyTheme” scope and set the scope as Web. Attach the Event Receiver

    1: <?xml version="1.0" encoding="utf-8"?>
    2: <Feature  Id="072b6290-252a-466d-9150-397d98c8f1c7"
    3:           Title="ApplyMyThemes"
    4:           Description="This feature will apply the custom them to the present site and site created in the future."
    5:           Version="12.0.0.0"
    6:           Hidden="FALSE"
    7:           Scope="Web"
    8:           DefaultResourceFile="core"
    9:           ReceiverAssembly="WSPBuilderProject1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cde4cc014c71f228"
   10:           ReceiverClass="WSPBuilderProject1.ApplyMyThemes"
   11:           xmlns="http://schemas.microsoft.com/sharepoint/">
   12: </Feature>

2. In the event receiver apply the new site theme. Following is the sample code :-

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.SharePoint;

namespace WSPBuilderProject1

{

class ApplyMyThemes : SPFeatureReceiver

    {

public override void FeatureActivated(SPFeatureReceiverProperties properties)

        {

            SPWeb web = (SPWeb)properties.Feature.Parent;

if(web.Url.Contains("7000"))

            {

                web.ApplyTheme("Belltown");

                web.Update();

            }

        }

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)

        {

        }

public override void FeatureInstalled(SPFeatureReceiverProperties properties)

        {

        }

public override void FeatureUninstalling(SPFeatureReceiverProperties properties)

        {

        }

    }

}

3. Create a stapler feature to attach the web feature with the Site definitions feature at “Farm”

    1: <?xml version="1.0" encoding="utf-8"?>
    2: <Feature Id="84379d76-8f8b-4259-a02e-f6047b88f6d4" 
    3: Title="Stappler"
    4: Description="Description for Stappler"
    5: Version="12.0.0.0"
    6: Hidden="FALSE"
    7: Scope="Farm"
    8: DefaultResourceFile="core"
    9: xmlns="http://schemas.microsoft.com/sharepoint/">
   10:   <ElementManifests>
   11:     <ElementManifest Location="elements.xml"/>    
   12:   </ElementManifests>
   13: </Feature>
   14:  

4. Staple the feature with the site definitions : -

    1: <?xml version="1.0" encoding="utf-8" ?>
    2: <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    3:   <FeatureSiteTemplateAssociation Id="072b6290-252a-466d-9150-397d98c8f1c7" TemplateName="STS#0" />
    4:   <FeatureSiteTemplateAssociation Id="072b6290-252a-466d-9150-397d98c8f1c7" TemplateName="STS#1" />
    5:   <FeatureSiteTemplateAssociation Id="072b6290-252a-466d-9150-397d98c8f1c7" TemplateName="STS#2" />
    6: </Elements>