SharePoint Online: How to Change the Header Banner Image in Modern Site Pages?
Requirement: Change the Header Banner Image in Modern Site Pages
How to Change the Header Background image in SharePoint Online Site Page?
Here is how to change the default header image on the 'Site Page' on SharePoint Online:
PnP PowerShell to Change Banner Image:
Here is the PnP PowerShell script to change the banner image in a site page:
Add Banner Image to All Pages in Site Pages Library
What if you want to change the banner image for all pages in "Site Pages" library?
How to Change the Header Background image in SharePoint Online Site Page?
Here is how to change the default header image on the 'Site Page' on SharePoint Online:
- Navigate to the modern site page. E.g. https://crescent.sharepoint.com/sites/marketing/SitePages/About-Us.aspx
- Click on "Edit" button on the top right area.
- Click on the top-header area to select it. Click on the little image icon as shown below.
- You can upload new image, use URL, or select an existing image for banner from the site. Once selected, drag and set a focal point.
- Save and publish the page.
PnP PowerShell to Change Banner Image:
Here is the PnP PowerShell script to change the banner image in a site page:
#Parameter $SiteURL= "https://crescent.sharepoint.com/sites/marketing/" $PageName = "About-us.aspx" $PageHeaderImage = "/sites/marketing/images/banner.png" #Server Relative URL #Connect to PnP Online Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential) #Get Client Side Page $Page = Get-PnPClientSidePage -Identity $PageName #Set page header image $Page.SetCustomPageHeader($PageHeaderImage) #Save and publish the page $Page.Save() $Page.Publish()
Add Banner Image to All Pages in Site Pages Library
What if you want to change the banner image for all pages in "Site Pages" library?
#Parameter $SiteURL= "https://crescent.sharepoint.com/sites/marketing" $LibraryName = "Site Pages" $PageHeaderImage = "/sites/marketing/SiteCollectionImages/banner.png" #Connect to PnP Online Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential) #Get all Pages from the Library $Pages = Get-PnPListItem -List $LibraryName #Loop through each Page ForEach($Page in $Pages) { #Get the Modern Site Page - Errors on Classic Pages $ClientSidePage = Get-PnPClientSidePage -Identity $Page.FieldValues.FileLeafRef -ErrorAction SilentlyContinue If($ClientSidePage) { Set-PnPClientSidePage -Identity $ClientSidePage -HeaderType Custom -ServerRelativeImageUrl $PageHeaderImage -Publish #-TranslateX 5.2 -TranslateY 10.5 Write-host -f Green "Changed Banner in Page:"$Page.FieldValues.FileRef } }
No comments:
Please Login and comment to get your questions answered!