Create Site Pages Library in SharePoint Online

Requirement: Create site pages library in SharePoint Online.

The Site Pages library is a unique library that stores the pages for your site. You can use the Site Pages library to create and store pages that can be used to share information and collaborate with your team. If the site pages library is missing/deleted for some reason, SharePoint Online sites start to display a “404 NOT FOUND” error! To create a site pages library in SharePoint Online, follow these steps:

Approach 1: Activate the “Site Pages” Feature to create the Site Pages Library

The “Site Pages” site-level feature brings the “Site Pages” library to the site. So, follow these steps and activate the feature to get the Site pages library.

  1. Navigate to your SharePoint Online site.
  2. Click on Settings >> Choose “Site Settings” (https://YourDomain.sharepoint.com/sites/YourSite/_layouts/15/settings.aspx))
  3. Click on “Manage site features” under the “Site Actions” group.
  4. Locate the “Site Pages” Feature and click on “Activate” next to it. If it’s already activated, Deactivate once and then activate it again.create site pages library in sharepoint online
  5. This will bring the missing “Site Pages” library. You can create a new site page and set it as the Home page for the site.

The site pages library will now appear in the “Site Contents” list. You can use this library to store and organize your site pages. You can also use it to create new pages, edit existing pages, and delete pages as needed.

Option 2: PowerShell to Create the Site Pages Library in SharePoint Online

In case, the above steps don’t work for you, Here is the PowerShell to create the site pages library in a SharePoint Online site. This PnP PowerShell script creates the Site Pages library and adds the “Site Page” content type to it.

#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Purchase"

Try {
    #Connect to SharePoint Online site
    Connect-PnPOnline -Url $SiteURL -Interactive

    #Get the context
    $Ctx = Get-PnPContext

    #Check if the Site Pages Library Exists
    $SitePagesLibrary = Get-PnPList -Identity "Site Pages" 
    
    If($SitePagesLibrary -eq $Null)
    {
        #Create Site Pages Library in sharepoint online using powershell
        $ListInfo = New-Object Microsoft.SharePoint.Client.ListCreationInformation
        $ListInfo.Title = "Site Pages"
        $ListInfo.Url = "SitePages"
        $ListInfo.TemplateType = 119 #Site Pages library template
        $List = $Ctx.Web.Lists.Add($ListInfo)
        $List.Update()
        Invoke-PnPQuery
        Write-host "Site Pages Library Created!" -f Green
    }
    Else
    {
        Write-Host -f Yellow "Site Pages Library already exist!"
    }

    #Add "Site Page" Content type to the "Site Pages" library
    $ContentType = Get-PnPContentType -Identity "Site Page"
    If($ContentType)
    {
        #Check if the Library has the content type already
        $SitePageContentType = Get-PnPContentType -List "Site Pages" -Identity "Site Page" -ErrorAction SilentlyContinue
        If(!$SitePageContentType)
        {
            #Add Content Type to Library
            Add-PnPContentTypeToList -List "Site Pages" -ContentType $ContentType
            Write-host "Site Page content type added to the Library" -f Green
        }
        Else
        {
            Write-host "Site Page content type already exists in the Library!" -f yellow
        }
    }
    Else
    {
        Write-host -f Yellow "Could Not Find the 'Site Page' Content Type! Activate the Site Pages Feature" -f Yellow
    }
}
Catch {
    Write-host -f Red "Error:" $_.Exception.Message
}

Once the site pages library is ready, you can create a new site page, add content to it and set it as the Home page.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

Your email address will not be published. Required fields are marked *