SharePoint Online: How to Change Site Theme using PowerShell?
In SharePoint Online, you can customize the look and feel of your site by changing themes to reflect your corporate branding. A theme in SharePoint Online defines the colors, fonts, images, and page layout for the SharePoint sites. SharePoint provides a default set of site themes, and we also have the ability to create and deploy our custom themes.
This post will guide you through the steps necessary to change your site theme. We’ll also share how you can change your SharePoint Online site theme using PowerShell so that you can quickly switch between different themes on your site without having to go through the Site Settings page and make the change manually.
How to Change the Theme in Classic SharePoint Online sites?
To change a theme for a site, do the following:
- Navigate to the SharePoint Online site where you want to change the theme >> On the site’s home page, Click on Settings gear >> Choose “Change the look” from the Site Settings menu.
- On the Change the Look page, select the theme to use as the starting point for the new site layout. (You can also go to Site Settings >> Click on the “Change the Look” link from the Look and Feel section)
- On the Change the Look configuration page, you can further customize the theme to meet your requirements, such as:
- You can change the background image (or remove it).
- The color scheme for the theme can be further changed by using the colors drop-down and select the desired color combination.
- The site master page layout can be changed to two available page layouts: Oslo and Seattle.
- The font family for use in the site can be selected. Select the font listing from the Fonts drop-down list.
- Once any changes to the theme’s background image, colors, site layout, and fonts have been made, the theme can be tested by clicking the “Try It Out” link. Clicking this link will generate a preview of the look. You see the layout as it will appear within the site.
- On the Preview page, decide whether the look is complete. Clicking the “No, Not Quite There” link returns you to the Change the Look configuration page, where you can customize the look and feel. Clicking the “Yes, Keep It” link changes the current theme of the site.
You can reset the Theme of a SharePoint Online site by switching to the “Office” theme! Go to Site settings >> Look and feel >> Change the look. >> Select the “Office” Theme and apply. This gets you the default Microsoft look. Any user with a “Design” or “Full Control” permission level can change site themes! Here is my other post on changing themes using PowerShell in SharePoint On-premises: How to Apply Theme using PowerShell in SharePoint?
The Theme Generator tool is available Online at: https://aka.ms/themedesigner
Themes Inheritance in Hub-Sites:
Themes are inherited across all sites associated with a hub! If you attempt to configure the look and feel of a site associated with a hub, you’ll be notified with “Your site is connected to the <Hub-site name> hub site and is set to adopt the same theme automatically.” message. So, To change the Theme for the associated sites, you’ll need to go to the hub site and set theme options there!
SharePoint Online: Apply theme using PowerShell
To change the SharePoint Theme programmatically, we need the Theme Url, Image Url, and Font Scheme URL of templates from the Composed Looks list. You can get them by navigating through “/_catalogs/design/AllItems.aspx” URL of your site collection.
#Import PowerShell Module for SharePoint Online
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
#Parameters for Processing
$SiteUrl = "https://crescent.sharepoint.com/sites/marketing"
$ColorPaletteUrl = "/sites/marketing/_catalogs/theme/15/palette002.spcolor"
$FontSchemeUrl = "/sites/marketing/_catalogs/theme/15/fontscheme002.spfont"
$BackgroundImageUrl = "/_layouts/15/images/image_bg002.jpg"
#Get Credentials to connect
$Cred= Get-Credential
Try {
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Get the Web
$Web = $Ctx.Web
$Ctx.Load($Web)
$Ctx.ExecuteQuery()
#Apply Theme
$Web.ApplyTheme($ColorPaletteUrl,$FontSchemeUrl,$BackgroundImageUrl,$True)
$Ctx.ExecuteQuery()
}
catch {
write-host "Error Changing Theme: $($_.Exception.Message)" -foregroundcolor Red
}
If you want to skip the Font scheme or background image parameters, Set those variables to Out-Null. E.g. $BackgroundImageUrl = Out-Null.
PowerShell to Apply Theme to Subsites in SharePoint Online:
Let’s change the Theme for all sites in a site collection in SharePoint Online.
#Import PoweShell Module for SharePoint Online
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
#Parameters for Processing
$SiteUrl = "https://crescent.sharepoint.com/sites/marketing"
#Theme URLs - Located only at Root Site
$ColorPaletteUrl = "/sites/marketing/_catalogs/theme/15/palette001.spcolor"
$FontSchemeUrl = "/sites/marketing/_catalogs/theme/15/fontscheme001.spfont"
$BackgroundImageUrl = "_layouts/15/images/image_bg001.jpg"
#Get Credentials to connect
$Cred = Get-Credential
Try {
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Get the Root web
$Web = $Ctx.Web
$Ctx.Load($Web)
$Ctx.ExecuteQuery()
#Function to change the site theme
Function Set-SPOSiteTheme($Web)
{
#Apply Theme
$Web.ApplyTheme($ColorPaletteUrl,$FontSchemeUrl,$BackgroundImageUrl,$True)
$Ctx.ExecuteQuery()
Write-host -f Green "Theme Applied on site '$($Web.Url)' Successfully!"
#Process each subsite in the site
$Subsites = $Web.Webs
$Ctx.Load($Subsites)
$Ctx.ExecuteQuery()
Foreach ($SubSite in $Subsites)
{
#Call the function Recursively
Set-SPOSiteTheme($Subsite)
}
}
#Call the function to change the theme of the web
Set-SPOSiteTheme($Web)
}
catch {
write-host "Error Changing Theme: $($_.Exception.Message)" -foregroundcolor Red
}
PnP PowerShell to Set Theme in SharePoint Online
Themes can be applied with the Set-PnPTheme cmdlet in SharePoint Online.
#Parameters
$SiteURL= "https://crescent.sharepoint.com/sites/marketing"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credential (Get-Credential) #-Interactive
#Change Set Theme
Set-PnPTheme -ColorPaletteUrl "/_catalogs/theme/15/palette008.spcolor" -BackgroundImageUrl "/_layouts/15/images/image_bg008.jpg" -FontSchemeUrl "/_catalogs/theme/15/fontscheme003.spfont"
Inherit Theme from the Parent Site using PnP PowerShell
We can inherit the Theme and apply it to subsites using -ResetSubwebsToInherit switch. Here is how:
Set-PnPTheme -ColorPaletteUrl "/_catalogs/theme/15/palette008.spcolor" -BackgroundImageUrl "/_layouts/15/images/image_bg008.jpg" -FontSchemeUrl "/_catalogs/theme/15/fontscheme003.spfont" -ResetSubwebsToInherit
This makes subsites inherit Theme!
You can reset themes by calling the cmdlet “Set-PnPTheme” without any parameters, which removes the theme from the site!
Conclusion
In conclusion, changing the site theme in SharePoint Online can be easily accomplished by using the web browser interface through the site settings page or PowerShell. The PowerShell way provides a convenient and automated way of managing the appearance of SharePoint sites, making it quick and easy to change the look and feel of your site. Whether you want to change the color scheme, font, or background, using PowerShell allows you to make these changes quickly and easily, without having to manually update each page of your site. This can be especially helpful for organizations with multiple sites, as the process can be easily automated, saving time and effort. By using PowerShell to change the site theme in SharePoint Online, organizations can improve the user experience, enhance the branding of their sites, and ensure that their content is presented in a visually appealing and professional manner.
Related posts:
- To apply a modern theme to the SharePoint Online site, use: SharePoint Online: Apply Modern Theme using PowerShell
- To add a custom theme in SharePoint Online, use: SharePoint Online: Add Custom Theme using PowerShell
Thank you so much dear! It works just amazing!!