I want to exclude certain URLs from the sitemap, depending on the custom field settings in their corresponding entries. I'm using SEO Matic plugin in craft4
Currently, the only facility for doing this would be to use an SEO Settings field in that field layout, and manually override the setting on a per-entry basis.
I can think of two possible solutions:
I allow the "Include in Sitemap" field to have a text entry option where you can enter Twig to put your custom condition
Trigger an event that a custom PHP module or plugin can listen for, and do the evaluation there in terms of whether the entry should be included in the sitemap or not
But before we go down that road, can you elaborate on what you're trying to accomplish here? Just excluding something from the sitemap alone does not prevent it from getting indexed.
More here: SEO Myths: Top 5 Sitemap Myths Demystified