Add custom columns (metadata) to “modern” SharePoint pages

In your Site Pages library let’s say you have a Wiki Page, a Webpart Page and a Site Page (i.e. modern page).

When I add a choice column, let’s call it TestChoiceCol, I can see the field in the edit form for the Wiki Page and Webpart page and can select a value and Save it as well.

However, the field does not show for the Site Page. This tells me metadata cannot be added to modern pages. That’s bad news for someone who wants to create information architecture and enable better search with refiners.

But turns out there’s a twist.

We have bad news and we have good news.

Let me dish out the bad news first.

You cant add the metadata (custom columns) via UI. Neither from edit properties page nor from the Modern page itself OOTB.

But we also have good news.

We can do it programmatically using CSOM C# or via PowerShell.

How will we do it?

Well according to Programming modern pages ,

creating a “modern” page comes down to creating a list item in the site pages library and assigning it the correct content type combined with setting some additional properties.

So, leveraging the code mentioned in the link, I added my custom column to it.

In the Site Pages library, I created a simple choice column named TestChoiceCol.
The options were – Oreo,Good-day and Parle-G.

In the library settings, I could see that this column was not associated with Site Pages content type.

Test Choice column

So, I ran the below code to add a modern page:

To update the modern page custom column, you can the run the below snippet:

Now,this code executes successfully. However, if I check the edit/view properties page, I couldn’t see the column.

Modern Site page Edit properties

But then I re-indexed the Site Pages library and mapped the crawled property ows_TestChoiceCol to a standard RefinableString managed property.

Mapping crawled property to managed property

Then I re-indexed the library and the site collection again, yes quite impatient aren’t we !!

After that, I created a standard search page with a search results webpart and a refiner webpart.

In the refiner webpart, I added my custom refinablestring property.

In the search results webpart, I filtered it to get only modern pages.

The search query was –

{searchboxquery} ContentTypeId:0x0101009D1CB255DA76424F860D91F20E6C4118*

Once done, we are able to now filter modern pages based on custom columns.

Modern page filter


The trick here is to treat the modern page as just another list item. You can then add as many custom columns or metadata that you want and then perform normal CRUD operations like the ones we do with standard list items.

The only drawback here, is that this not possible via UI for now.

That needs to change. To ensure that your voices are heard by Microsoft, please do upvote on the user voice link mentioned below:

Enable custom columns for modern pages


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s