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.
  • 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:
$SiteURL= ""
$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

#Save and publish the 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?
$SiteURL= ""
$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

        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!

Powered by Blogger.