1

Is it possible to create a custom theme in Modern sites and deploy it only at the site collection level? Just like we have option to create a site collection app catalog?

0

You can create a new theme if you are a SharePoint tenant administrator. Themes are applied to separate subsites, not to entire site collections. But you can apply a theme to an all individual subsites with a PowerShell.

Steps

  • Open PowerShell ISE as an administrator

    enter image description here

  • Install PowerShell PnP Module by running the following command:

Install-Module SharePointPnPPowerShellOnline
  • Connect to your target site collection:
$TargetSiteUrl = "https://tenant.sharepoint.com/sites/MySiteCollection"
Connect-PnPOnline -Url $TargetSiteUrl
  • Open Site for Modern Theme geration > Apply Primary and secondary color of your choice.
  • Click "Export Theme" > PowerShell tab and copy the code to your clipboard and paste to PowerShell into the $ThemeHash variable like so:
$themeHash = @{
"themePrimary" = "#0078d4";
"themeLighterAlt" = "#f3f9fd";
"themeLighter" = "#d0e7f8";
"themeLight" = "#a9d3f2";
"themeTertiary" = "#5ca9e5";
"themeSecondary" = "#1a86d9";
"themeDarkAlt" = "#006cbe";
"themeDark" = "#005ba1";
"themeDarker" = "#004377";
"neutralLighterAlt" = "#f8f8f8";
"neutralLighter" = "#f4f4f4";
"neutralLight" = "#eaeaea";
"neutralQuaternaryAlt" = "#dadada";
"neutralQuaternary" = "#d0d0d0";
"neutralTertiaryAlt" = "#c8c8c8";
"neutralTertiary" = "#bab8b7";
"neutralSecondary" = "#a3a2a0";
"neutralPrimaryAlt" = "#8d8b8a";
"neutralPrimary" = "#323130";
"neutralDark" = "#605e5d";
"black" = "#494847";
"white" = "#ffffff";
}

enter image description here

  • Add theme to the tenant by running this code:
Add-PnPTenantTheme -Identity "Corporate Theme" -Palette $themeHash -IsInverted $false -Overwrite
  • Apply theme to the target site:
# Apply theme to the root web of the site collection
Set-PnPWebTheme -Theme "Corporate Theme" -WebUrl $TargetSiteUrl
  • Apply theme to all subsites recursively:
# Apply theme to all subsites recursively
Get-PnPSubWebs -Recurse | % {Set-PnPWebTheme -Theme "Corporate Theme" -Web $_}

Full Code


Install-Module SharePointPnPPowerShellOnline

$TargetSiteUrl = "https://tenant.sharepoint.com/sites/MySiteCollection"
Connect-PnPOnline -Url $TargetSiteUrl

# URL for generating themes: https://fabricweb.z5.web.core.windows.net/pr-deploy-site/refs/pull/8933/merge/theming-designer/index.html
$themeHash = @{
    "themePrimary" = "#0078d4";
    "themeLighterAlt" = "#f3f9fd";
    "themeLighter" = "#d0e7f8";
    "themeLight" = "#a9d3f2";
    "themeTertiary" = "#5ca9e5";
    "themeSecondary" = "#1a86d9";
    "themeDarkAlt" = "#006cbe";
    "themeDark" = "#005ba1";
    "themeDarker" = "#004377";
    "neutralLighterAlt" = "#f8f8f8";
    "neutralLighter" = "#f4f4f4";
    "neutralLight" = "#eaeaea";
    "neutralQuaternaryAlt" = "#dadada";
    "neutralQuaternary" = "#d0d0d0";
    "neutralTertiaryAlt" = "#c8c8c8";
    "neutralTertiary" = "#bab8b7";
    "neutralSecondary" = "#a3a2a0";
    "neutralPrimaryAlt" = "#8d8b8a";
    "neutralPrimary" = "#323130";
    "neutralDark" = "#605e5d";
    "black" = "#494847";
    "white" = "#ffffff";
}

Add-PnPTenantTheme -Identity "Corporate Theme" -Palette $themeHash -IsInverted $false -Overwrite

# Apply theme to the root web of the site collection
Set-PnPWebTheme -Theme "Corporate Theme" -WebUrl $TargetSiteUrl

# Apply theme to all subsites recursively
Get-PnPSubWebs -Recurse | % {Set-PnPWebTheme -Theme "Corporate Theme" -Web $_}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.