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:
  • 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. 
    sharepoint online add banner image
  • Click on the top-header area to select it. Click on the little image icon as shown below.
    sharepoint online header background image
  • 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.
    sharepoint online change header image
Tips:  Here is the Sharepoint Online modern page banner image size recommendations from Microsoft: Banner Image Size Reference for SharePoint Online


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
    }
}
SharePoint Online: How to Change the Header Banner Image in Modern Site Pages? SharePoint Online: How to Change the Header Banner Image in Modern Site Pages? Reviewed by Salaudeen Rajack on March 24, 2019 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.