Is it possible to reference the same .css in various master pages across site collections
-
05-02-2021 - |
Вопрос
I have about 10 site collections on SharePoint 2016 on-prem that I want to brand with our custom .css. I have the .css working great in one of the site collections, but I'm curious about how to apply to the rest of the site collections.
Here's how I link the .css in my master page :
<link rel="stylesheet" type="text/css" href="<% $SPUrl:~SiteCollection/Style Library/Susan.css%>" runat="server"/>
Is there a way to use the .css across site collections?
Решение
You can set location of CSS file through PowerShell:
$site = Get-SPSite https://mysitecollection
foreach ($web in $site.AllWebs)
{
$web.AlternateCssUrl = $site.Url + "/Style Library/Susan.css"
$web.Update();
Write-Host "Set CSS for site " + $web.Url
}
$site.Dispose()
EDIT:
Here is a solution without PowerShell. You basically create a copy of your master page, modify it with your CSS file and use that as master page for your all sites. Please take note of creating a copy of the master page as it's basically a bad idea to modify stuff that's in use by SharePoint.
Then afterwards you just have to set the new master page across your site collections.