Modify sitemap.xml

Hello everybody!
Is there a way to change the sitemap.xml code for search engines so I could choose the pages I want to have in it?

this is the code:

<?= '<?xml version="1.0" encoding="utf-8"?>'; ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <?php foreach ($pages as $p): ?>
        <?php if (in_array($p->uri(), $ignore)) continue ?>
        <url>
            <loc><?= html($p->url()) ?></loc>
            <lastmod><?= $p->modified('c', 'date') ?></lastmod>
            <priority><?= ($p->isHomePage()) ? 1 : number_format(0.5 / $p->depth(), 1) ?></priority>
        </url>
    <?php endforeach ?>
</urlset>

Right now there are only irrelevant pages. I would like pick the most relevant pages, for example - only the pages that are in the nav bar. is it possible?

Thanks!

What goes into the sitemap is defined inside the route: Sitemap for search engines | Kirby CMS

$pages = site()->pages()->index();

So that’s all published pages of the site. You can either define a different collection or exclude pages as explained in the recipe.

1 Like